<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>file reading and writing in php - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/file-reading-and-writing-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/file-reading-and-writing-in-php/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 01 Aug 2022 05:45:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>file reading and writing in php - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/file-reading-and-writing-in-php/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to read a file in PHP ?</title>
		<link>https://www.wikitechy.com/interview-questions/php/how-to-read-a-file-in-php/</link>
					<comments>https://www.wikitechy.com/interview-questions/php/how-to-read-a-file-in-php/#respond</comments>
		
		<dc:creator><![CDATA[webmaster]]></dc:creator>
		<pubDate>Mon, 01 Aug 2022 05:45:29 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[file reading and writing in php]]></category>
		<category><![CDATA[fopen php]]></category>
		<category><![CDATA[how to read a file in php]]></category>
		<category><![CDATA[how to read a file in php file]]></category>
		<category><![CDATA[php file example]]></category>
		<category><![CDATA[php file open/read/close]]></category>
		<category><![CDATA[php file reader]]></category>
		<category><![CDATA[php files & i/o]]></category>
		<category><![CDATA[php read file]]></category>
		<category><![CDATA[php read text file line by line]]></category>
		<category><![CDATA[php readfile() function]]></category>
		<category><![CDATA[read a file in php]]></category>
		<category><![CDATA[read a plain text file with php]]></category>
		<category><![CDATA[read text files in php]]></category>
		<category><![CDATA[writing files in php]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=4515</guid>

					<description><![CDATA[PHP File provides various functions to read data. There are different functions that allow you to read all file data, read data character by character and read data line by line. The PHP file available read functions are given below, they are: fread () fgets () fgetc () PHP Read File- fread () PHP fread [&#8230;]]]></description>
										<content:encoded><![CDATA[<ul>
<li style="text-align: justify;"><a href="https://www.wikitechy.com/php/">PHP</a> File provides various functions to read data.</li>
<li style="text-align: justify;">There are different functions that allow you to read all file data, read data character by character and read data line by line.</li>
<li style="text-align: justify;">The PHP file available read functions are given below, they are:</li>
</ul>
<ol style="text-align: justify;">
<li style="list-style-type: none;">
<ol>
<li>fread ()</li>
<li>fgets ()</li>
<li>fgetc ()</li>
</ol>
</li>
</ol>
<h2 id="php-read-file-fread" style="text-align: justify;"><strong>PHP Read File- fread ()</strong></h2>
<ul style="text-align: justify;">
<li>PHP fread () function is used to read data of the file and it consists of two arguments, they are file size and file resource.</li>
</ul>
<h3 id="sample-code" style="text-align: justify;"><strong>Sample Code</strong></h3>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-php code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-php code-embed-code">&lt;?php    <br/>$filename = &quot;c:\\file1.txt&quot;;    <br/>$fp = fopen($filename, &quot;r&quot;);//open file in read mode    <br/>  <br/>$contents = fread($fp, filesize($filename));//read file    <br/>  <br/>echo &quot;&lt;pre&gt;$contents&lt;/pre&gt;&quot;;//printing data of file  <br/>fclose($fp);//close file    <br/>?&gt;   </code></pre> </div>
<h3 id="output" style="text-align: justify;"><strong>Output</strong></h3>
<p style="text-align: justify;"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4516" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function.png" alt="" width="1425" height="261" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function.png 1425w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-300x55.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-1024x188.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-768x141.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-390x71.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-820x150.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fread-function-1180x216.png 1180w" sizes="(max-width: 1425px) 100vw, 1425px" /></p>
<h2 id="php-read-file-fgets" style="text-align: justify;">PHP Read file- fgets ()</h2>
<ul style="text-align: justify;">
<li>To read single line from the file PHP fgets () function is used.</li>
</ul>
<h3 id="sample-code-2" style="text-align: justify;"><strong>Sample Code</strong></h3>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-php code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-php code-embed-code">&lt;?php    <br/>$fp = fopen(&quot;c:\\file1.txt&quot;, &quot;r&quot;);//open file in read mode    <br/>echo fgets($fp);  <br/>fclose($fp);  <br/>?&gt;   </code></pre> </div>
<h3 id="output-2" style="text-align: justify;"><strong>Output</strong></h3>
<p style="text-align: justify;"><img decoding="async" class="alignnone size-full wp-image-4517" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function.png" alt="" width="1430" height="151" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function.png 1430w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-300x32.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-1024x108.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-768x81.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-390x41.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-820x87.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgets-function-1180x125.png 1180w" sizes="(max-width: 1430px) 100vw, 1430px" /></p>
<h2 id="php-read-file-fgetc" style="text-align: justify;">PHP Read file- fgetc ()</h2>
<ul style="text-align: justify;">
<li>To read single character from the file PHP fgetc () function is used and use! feof () function inside the while loop to get all data using fgetc () function.</li>
</ul>
<h3 id="sample-code-3" style="text-align: justify;"><strong>Sample Code</strong></h3>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-php code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-php code-embed-code">&lt;?php    <br/>$fp = fopen(&quot;c:\\file1.txt&quot;, &quot;r&quot;);//open file in read mode    <br/>while(!feof($fp)) {  <br/>  echo fgetc($fp);  <br/>}  <br/>fclose($fp);  <br/>?&gt;    </code></pre> </div>
<h3 id="output-3" style="text-align: justify;"><strong>Output</strong></h3>
<p style="text-align: justify;"><img decoding="async" class="alignnone size-full wp-image-4518" src="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function.png" alt="" width="1424" height="150" srcset="https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function.png 1424w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-300x32.png 300w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-1024x108.png 1024w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-768x81.png 768w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-390x41.png 390w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-820x86.png 820w, https://www.wikitechy.com/interview-questions/wp-content/uploads/2022/08/fgetc-function-1180x124.png 1180w" sizes="(max-width: 1424px) 100vw, 1424px" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/php/how-to-read-a-file-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
