{"id":16155,"date":"2025-05-01T11:29:48","date_gmt":"2025-05-01T09:29:48","guid":{"rendered":"https:\/\/www.beseit.net\/?p=16155"},"modified":"2025-05-01T11:38:02","modified_gmt":"2025-05-01T09:38:02","slug":"funcio-escriu_a_fitxer","status":"publish","type":"post","link":"http:\/\/www.beseit.net\/?p=16155","title":{"rendered":"Funci\u00f3: escriu_a_fitxer usant (usant __DIR__)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#eb0a0a\" class=\"has-inline-color\">El directori on es crea el fitxer \u00e9s on es troba el fitxer PHP actual (usant <code>__DIR__<\/code>)<\/mark><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nfunction escriu_a_fitxer($nomFitxerRelatiu, $contingut, $afegir = false) {\n    \/\/ Ruta completa del fitxer\n    $ruta = __DIR__ . '\/' . $nomFitxerRelatiu;\n\n    \/\/ Mode d'obertura: 'a' per afegir, 'w' per sobreescriure\n    $mode = $afegir ? 'a' : 'w';\n\n    $fp = fopen($ruta, $mode);\n    if (!$fp) {\n        echo \"Error: no s'ha pogut obrir el fitxer $ruta.\";\n        return false;\n    }\n\n    fwrite($fp, $contingut);\n    fclose($fp);\n    echo \"Fitxer escrit correctament a: $ruta&lt;br&gt;\";\n    return true;\n}\n?&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>El directori on es crea el fitxer \u00e9s on es troba el fitxer PHP actual (usant __DIR__)<\/p>\n","protected":false},"author":2,"featured_media":3169,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"class_list":["post-16155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16155"}],"version-history":[{"count":3,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16155\/revisions"}],"predecessor-version":[{"id":16160,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/posts\/16155\/revisions\/16160"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=\/wp\/v2\/media\/3169"}],"wp:attachment":[{"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16155"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.beseit.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}