{"id":77355,"date":"2022-09-18T06:59:11","date_gmt":"2022-09-18T06:59:11","guid":{"rendered":"https:\/\/itsourcecode.com\/?p=77355"},"modified":"2023-11-21T09:09:51","modified_gmt":"2023-11-21T09:09:51","slug":"php-file-io-with-example-program","status":"publish","type":"post","link":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/","title":{"rendered":"PHP File IO with Example Program"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"open-file\"><strong>PHP Open File &#8211; fopen()<\/strong><\/h2>\n\n\n\n<p>The <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fopen()<\/mark><\/code> function is a better way to open files. This function is better than the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">readfile()<\/mark><\/code> function because it gives you more options.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>During the lessons, we will use the text file &#8220;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">phptutorial.txt<\/mark><\/code>&#8220;:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>AJAX<\/td><td>Asynchronous JavaScript and XML<\/td><\/tr><tr><td>CSS<\/td><td>Cascading Style Sheets<\/td><\/tr><tr><td>HTML<\/td><td>Hyper Text Markup Language<\/td><\/tr><tr><td>PHP<\/td><td>PHP Hypertext Preprocessor<\/td><\/tr><tr><td>SQL<\/td><td>Structured Query Language<\/td><\/tr><tr><td>SVG<\/td><td>Scalable Vector Graphics<\/td><\/tr><tr><td>XML<\/td><td>eXtensible Markup Language<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The first parameter of the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fopen()<\/mark><\/code> function is the name of the file to be opened, and the second parameter tells <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fopen()<\/mark><\/code> how to open the file. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fopen()<\/mark><\/code> function is unable to open the specified file, the following example will also print a message:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><merlin-component id=\"merlin-code-summarizer\" class=\"merlin-code-summarizer\"><\/merlin-component><code>&lt;?php\n$file_txt = fopen(\"phptutorial.txt\", \"r\") or die(\"Can't open file. Please try again!\");\necho fread($file_txt,filesize(\"phptutorial.txt\"));\nfclose($file_txt);\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The file may be opened in one of the following modes:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th class=\"has-text-align-center\" data-align=\"center\"><strong>Modes<\/strong><\/th><th><strong>Description<\/strong><\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">r<\/td><td>Open a file as a <strong>read-only<\/strong> file. The file pointer starts at the file&#8217;s beginning.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">w<\/td><td>Open a file as a <strong>write-only<\/strong> file. Deletes the file&#8217;s contents or, if the file does not exist, creates it. The file pointer begins at the file&#8217;s beginning.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">a<\/td><td>Open a file as a <strong>write-only<\/strong> file. Existing data in the file is maintained. The file pointer starts at the file&#8217;s end. Creates a file if it does not already exist.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">x<\/td><td><strong>Creates a new file as a write-only<\/strong>. If the file already exists, returns <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">FALSE<\/mark><\/code> with an error.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">r+<\/td><td><strong>Open a file as a read\/write. <\/strong>The file pointer starts at the file&#8217;s beginning.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">w+<\/td><td><strong>Open a file as a <strong>read\/write<\/strong> file<\/strong>. Deletes the file&#8217;s contents or, if the file does not exist, creates it. The file pointer begins at the file&#8217;s beginning.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">a+<\/td><td><strong>Open a file as a read\/<strong>write<\/strong> file<\/strong>. Existing data in the file is maintained. The file pointer starts at the file&#8217;s end. Creates a file if it does not already exist.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">x+<\/td><td><strong><strong>Creates a new file as a read\/write<\/strong><\/strong>. If the file already exists, returns <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">FALSE<\/mark><\/code> with an error.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"read-file\"><strong>PHP Read File &#8211; fread()<\/strong><\/h2>\n\n\n\n<p>The&nbsp;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fread()<\/mark><\/code>&nbsp;function reads from a file that is open.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The first parameter to <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fread()<\/mark><\/code> indicates the file to read from, while the second defines the maximum number of bytes to read.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The PHP code below reads the entire &#8220;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">phptutorial.txt<\/mark><\/code>&#8221; file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php\nfread($file_txt,filesize(\"phptutorial.txt\"));\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"close-file\"><strong>PHP Close File &#8211; fclose()<\/strong><\/h2>\n\n\n\n<p>A file is closed using the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fclose()<\/mark><\/code> method.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>It is best practice for programmers to close all files when they are no longer needed. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You do not want an open file running around on your server, using resources!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The function <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fclose()<\/mark><\/code> requires the filename (or a variable containing the filename) to be closed:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php\n$file_txt = fopen(\"phptutorial.txt\", \"r\");\n\/\/ code here\nfclose($file_txt );\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"read-single-line\"><strong>PHP Read Single Line &#8211; fgets()<\/strong><\/h2>\n\n\n\n<p>In the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fgets()<\/mark><\/code> function, we can read one line from a file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The &#8220;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">phptutorial.txt<\/mark><\/code>&#8221; file&#8217;s first line is shown in the example below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php\n$file_txt = fopen(\"phptutorial.txt\", \"r\") or die(\"Can't to open file!\");\necho fgets($file_txt);\nfclose($file_txt);\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Note<\/strong>: When the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fgets()<\/mark><\/code> function is called, the file pointer moves to the next line.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-end-of-file\"><strong>PHP Check End-Of-File &#8211; feof()<\/strong><\/h2>\n\n\n\n<p>The <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">feof()<\/mark><\/code> function checks if the file has reached the &#8220;<strong>end-of-file<\/strong>&#8221; (<strong>EOF<\/strong>).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">feof()<\/mark><\/code> function is handy for iterating through data with an uncertain length.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The following example reads the &#8220;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">phptutorial.txt<\/mark><\/code>&#8221; file line by line until it reaches the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php\n$file_txt = fopen(\"phptutorial.txt\", \"r\") or die(\"Can't open file!\");\n\n\/\/ Output a single line till the file's end\nwhile(!feof($file_txt)) {\n  echo fgets($file_txt) . \"&lt;br&gt;\";\n}\n\nfclose($file_txt);\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"read-single-character\"><strong>PHP Read Single Character &#8211; fgetc()<\/strong><\/h2>\n\n\n\n<p>The <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fgetc()<\/mark><\/code> function reads a single character from a file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The following example reads the &#8220;<code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">phptutorial.txt<\/mark><\/code>&#8221; file character by character until it reaches the end of the file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;?php\n$file_txt = fopen(\"phptutorial.txt\", \"r\") or die(\"Can't open file!\");\n\n\/\/ Output one character until end-of-file\nwhile(!feof($file_txt)) {\n  echo fgetc($file_txt);\n}\n\nfclose($file_txt);\n?&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>After calling the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fgetc()<\/mark><\/code> method, the file pointer advances to the following character.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-ask-question\"><strong>Frequently Ask Questions (FAQs)<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-do-i-read-a-php-file\"><strong>How do I read a PHP file?<\/strong><\/h3>\n\n\n\n<p>To read a PHP file, first we are going to open the file by using the function called <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fopen()<\/mark><\/code>. Then, to get the file length, we&#8217;re going to use the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">filesize()<\/mark><\/code> function.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Then, to read the PHP file, we are going to <strong>use the <\/strong><code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fread()<\/mark><\/code><strong> function<\/strong>. Finally, don&#8217;t forget to close the file, so to close it we are going to use the <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fclose()<\/mark><\/code> function.<\/p>\n\n\n\n<p>Additional information about <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fread()<\/mark><\/code> function from <a href=\"https:\/\/www.php.net\/manual\/en\/function.fread.php\">PHP Official Documentation<\/a>, <code><mark style=\"background-color:var(--base-3);color:#ff0000\" class=\"has-inline-color\">fread()<\/mark><\/code>&nbsp;reads up to&nbsp;<code>length<\/code>&nbsp;bytes from the file pointer referenced by&nbsp;<code>stream<\/code>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-the-php-file\"><strong>What is the PHP file?<\/strong><\/h3>\n\n\n\n<p>A PHP file is often a <strong>plain-text file containing PHP code<\/strong>. Since PHP is a server-side (back-end) scripting language, the PHP file contains code that is executed on the server.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The PHP engine on the web server turns all PHP code into HTML. This means that when the web page is sent to the client side to be displayed in the user&#8217;s browser, it only has HTML code.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-php-file-handler\"><strong>What is a PHP file handler?<\/strong><\/h3>\n\n\n\n<p>The PHP File System enables us to <strong>create files, read them line by line, character by character, write them, append them, delete them, and close them.<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"where-can-i-open-a-php-file\"><strong>Where can I open a PHP file?<\/strong><\/h3>\n\n\n\n<p>A PHP file is a simple text file, therefore it can be opened with any text editor, such as <strong>Atom<\/strong>, <strong>Notepad<\/strong>, or <strong>Sublime Text<\/strong>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Sublime Text<\/strong> should be enough for beginners, as they will only execute little code bits.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>However, as you go to more advanced PHP programming.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You should consider upgrading to advanced editors and integrated development environments (IDEs) that provide syntax highlighting syntax auto-completion, and extensive search capabilities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"how-do-php-files-work\"><strong>How do PHP files work?<\/strong><\/h3>\n\n\n\n<p>The PHP executes system actions, including the creation, opening, reading, and closing of system files. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>It is capable of managing formats, thus it can gather data from databases, store data in a file, transmit data via email, and return data to the user. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>PHP also allows you to add, delete, and modify database items.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-related-articles\"><strong>Related Articles<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/file-inclusion-in-php-with-program-examples\/\">File Inclusion in PHP (With Program Examples)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/free-projects\/php-project\/array-push-php-with-detailed-explanation\/\">Array Push PHP (With Detailed Explanation)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-array_merge-with-detailed-explanation\/\">PHP array_merge With Detailed Explanation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-includes-with-detailed-explanation\/\">PHP includes With Detailed Explanation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/itsourcecode.com\/php-tutorial\/creating-a-file-in-php-with-examples\/\">Creating a file in PHP With Examples<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\"><strong>Summary<\/strong><\/h2>\n\n\n\n<p>In summary, we have studied the different filesystem functions in PHP. We also included examples to help you better comprehend each function.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Lastly, if you want to learn more about PHP File IO, please leave a comment below. We\u2019ll be happy to hear it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP Open File &#8211; fopen() The fopen() function is a better way to open files. This function is better than the readfile() function because it gives you more options. During &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"PHP File IO with Example Program\" class=\"read-more button\" href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#more-77355\" aria-label=\"Read more about PHP File IO with Example Program\">Read more<\/a><\/p>\n","protected":false},"author":1373,"featured_media":77284,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61035],"tags":[95172,95174,95171,95173,95175],"class_list":["post-77355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-tutorial","tag-file-io-in-php","tag-file-io-php-example","tag-php-file-io","tag-php-file-io-example","tag-what-is-file-io-in-php","resize-featured-image"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PHP File IO with Example Program<\/title>\n<meta name=\"description\" content=\"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here&#039;s a simple example of how to do it in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP File IO with Example Program\" \/>\n<meta property=\"og:description\" content=\"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here&#039;s a simple example of how to do it in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/\" \/>\n<meta property=\"og:site_name\" content=\"Itsourcecode.com\" \/>\n<meta property=\"article:author\" content=\"www.facebook.com\/unguardable7\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-18T06:59:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-21T09:09:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1460\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prince Ly Cesar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/www.twitter.com\/unguardable0729\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prince Ly Cesar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/\"},\"author\":{\"name\":\"Prince Ly Cesar\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/8d6ff1c108160ddbd60ff17cbb9f626b\"},\"headline\":\"PHP File IO with Example Program\",\"datePublished\":\"2022-09-18T06:59:11+00:00\",\"dateModified\":\"2023-11-21T09:09:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/\"},\"wordCount\":977,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-file-io.png\",\"keywords\":[\"file io in php\",\"file io php example\",\"php file io\",\"php file io example\",\"what is file io in php\"],\"articleSection\":[\"PHP Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/\",\"name\":\"PHP File IO with Example Program\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-file-io.png\",\"datePublished\":\"2022-09-18T06:59:11+00:00\",\"dateModified\":\"2023-11-21T09:09:51+00:00\",\"description\":\"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here's a simple example of how to do it in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#primaryimage\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-file-io.png\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/php-file-io.png\",\"width\":1460,\"height\":900,\"caption\":\"php file io\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/php-tutorial\\\/php-file-io-with-example-program\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsourcecode.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP File IO with Example Program\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#website\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/\",\"name\":\"Itsourcecode.com\",\"description\":\"Partner In Your Coding Journey!\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsourcecode.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/ad9e0497e03b85a9ca299d935298f5dc\",\"name\":\"itsourcecode\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\",\"width\":409,\"height\":409,\"caption\":\"itsourcecode\"},\"logo\":{\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/IT-SOURCECODE_ICON-07.jpg\"},\"description\":\"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!\",\"sameAs\":[\"https:\\\/\\\/itsourcecode.com\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/#\\\/schema\\\/person\\\/8d6ff1c108160ddbd60ff17cbb9f626b\",\"name\":\"Prince Ly Cesar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"contentUrl\":\"https:\\\/\\\/itsourcecode.com\\\/wp-content\\\/litespeed\\\/avatar\\\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215\",\"caption\":\"Prince Ly Cesar\"},\"description\":\"Hi there! I'm Prince Ly Cesar a Student in Carlos Hilado Memorial State College - Binalbagan Campus and a Graphic Designer, Programmer &amp; Writer in IT SourceCode\",\"sameAs\":[\"https:\\\/\\\/activadorkeys.com\\\/\",\"www.facebook.com\\\/unguardable7\",\"http:\\\/\\\/www.instagram.com\\\/prnclycsr\\\/\",\"https:\\\/\\\/x.com\\\/http:\\\/\\\/www.twitter.com\\\/unguardable0729\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCF0BIqB5tpnCmwvYQCHucmw?view_as=subscriber\"],\"gender\":\"male\",\"knowsAbout\":[\"Graphic Designing\"],\"knowsLanguage\":[\"English\",\"Tagalog\"],\"jobTitle\":\"Graphic Designer\",\"worksFor\":\"IT SourceCode\",\"url\":\"https:\\\/\\\/itsourcecode.com\\\/author\\\/unguardable\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP File IO with Example Program","description":"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here's a simple example of how to do it in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/","og_locale":"en_US","og_type":"article","og_title":"PHP File IO with Example Program","og_description":"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here's a simple example of how to do it in PHP.","og_url":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/","og_site_name":"Itsourcecode.com","article_author":"www.facebook.com\/unguardable7","article_published_time":"2022-09-18T06:59:11+00:00","article_modified_time":"2023-11-21T09:09:51+00:00","og_image":[{"width":1460,"height":900,"url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png","type":"image\/png"}],"author":"Prince Ly Cesar","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/www.twitter.com\/unguardable0729","twitter_misc":{"Written by":"Prince Ly Cesar","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#article","isPartOf":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/"},"author":{"name":"Prince Ly Cesar","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/8d6ff1c108160ddbd60ff17cbb9f626b"},"headline":"PHP File IO with Example Program","datePublished":"2022-09-18T06:59:11+00:00","dateModified":"2023-11-21T09:09:51+00:00","mainEntityOfPage":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/"},"wordCount":977,"commentCount":0,"publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"image":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png","keywords":["file io in php","file io php example","php file io","php file io example","what is file io in php"],"articleSection":["PHP Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/","url":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/","name":"PHP File IO with Example Program","isPartOf":{"@id":"https:\/\/itsourcecode.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#primaryimage"},"image":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#primaryimage"},"thumbnailUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png","datePublished":"2022-09-18T06:59:11+00:00","dateModified":"2023-11-21T09:09:51+00:00","description":"PHP File IO is a PHP library for opening, reading, writing, and manipulating files, and here's a simple example of how to do it in PHP.","breadcrumb":{"@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#primaryimage","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2022\/09\/php-file-io.png","width":1460,"height":900,"caption":"php file io"},{"@type":"BreadcrumbList","@id":"https:\/\/itsourcecode.com\/php-tutorial\/php-file-io-with-example-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsourcecode.com\/"},{"@type":"ListItem","position":2,"name":"PHP File IO with Example Program"}]},{"@type":"WebSite","@id":"https:\/\/itsourcecode.com\/#website","url":"https:\/\/itsourcecode.com\/","name":"Itsourcecode.com","description":"Partner In Your Coding Journey!","publisher":{"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsourcecode.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/ad9e0497e03b85a9ca299d935298f5dc","name":"itsourcecode","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","url":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg","width":409,"height":409,"caption":"itsourcecode"},"logo":{"@id":"https:\/\/itsourcecode.com\/wp-content\/uploads\/2021\/01\/IT-SOURCECODE_ICON-07.jpg"},"description":"Hello Itsourcecoders, welcome to itsourcecode.com. I'm Joken Villanueva, MIT a passionate Blogger, Programmer and a Hobbyist. I started Itsourcecode because I wanted to give back and Share all the learnings and knowledge I've learned in my career and I believe through this website I would be able to help and assist those newbie programmers in enhancing their skills from different programming languages. So let us all help each other by sharing our ideas!","sameAs":["https:\/\/itsourcecode.com\/"]},{"@type":"Person","@id":"https:\/\/itsourcecode.com\/#\/schema\/person\/8d6ff1c108160ddbd60ff17cbb9f626b","name":"Prince Ly Cesar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","url":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","contentUrl":"https:\/\/itsourcecode.com\/wp-content\/litespeed\/avatar\/8fc9fa13530f18706fe0948f4673fae8.jpg?ver=1776478215","caption":"Prince Ly Cesar"},"description":"Hi there! I'm Prince Ly Cesar a Student in Carlos Hilado Memorial State College - Binalbagan Campus and a Graphic Designer, Programmer &amp; Writer in IT SourceCode","sameAs":["https:\/\/activadorkeys.com\/","www.facebook.com\/unguardable7","http:\/\/www.instagram.com\/prnclycsr\/","https:\/\/x.com\/http:\/\/www.twitter.com\/unguardable0729","https:\/\/www.youtube.com\/channel\/UCF0BIqB5tpnCmwvYQCHucmw?view_as=subscriber"],"gender":"male","knowsAbout":["Graphic Designing"],"knowsLanguage":["English","Tagalog"],"jobTitle":"Graphic Designer","worksFor":"IT SourceCode","url":"https:\/\/itsourcecode.com\/author\/unguardable\/"}]}},"_links":{"self":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/users\/1373"}],"replies":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/comments?post=77355"}],"version-history":[{"count":7,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77355\/revisions"}],"predecessor-version":[{"id":120576,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/posts\/77355\/revisions\/120576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media\/77284"}],"wp:attachment":[{"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/media?parent=77355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/categories?post=77355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsourcecode.com\/wp-json\/wp\/v2\/tags?post=77355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}