<?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>fgets() Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/fgets/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/fgets/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Mon, 16 Aug 2021 12:37:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Tutorial for fgets() in Reading file</title>
		<link>https://www.scmgalaxy.com/tutorials/tutorial-for-fgets-in-reading-file/</link>
					<comments>https://www.scmgalaxy.com/tutorials/tutorial-for-fgets-in-reading-file/#respond</comments>
		
		<dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
		<pubDate>Mon, 16 Aug 2021 12:37:12 +0000</pubDate>
				<category><![CDATA[php]]></category>
		<category><![CDATA[fgets()]]></category>
		<category><![CDATA[fgets() Reading file function in php]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[php Reading file]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[Reading file function in php]]></category>
		<category><![CDATA[Reading file in php]]></category>
		<category><![CDATA[Tutorial for fgets() in Reading file]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7979</guid>

					<description><![CDATA[<p>What is fgets() used in Reading file? This function is used to read a single line from a file. You [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/tutorial-for-fgets-in-reading-file/">Tutorial for fgets() in Reading file</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">What is fgets() used in Reading file?</h3>



<p class="wp-block-paragraph">This function is used to read a single line from a file. You can pass this function a file handle corresponding to an open file, and optional length.</p>



<h3 class="wp-block-heading">Why fgets() used in Reading file? </h3>



<ul class="wp-block-list"><li>It returns a line from a file pointer and terminates at a given length, end of file(EOF), or new line, whichever comes first.</li><li>The <code><span class="has-inline-color has-vivid-red-color"><strong>fgets()</strong></span></code> function is passed the file to read and the number of bytes to read as arguments, and it returns a string of length -1 bytes from the file indicated by the user.</li><li>If it fails, it returns False.</li></ul>



<p class="wp-block-paragraph"><strong>Syntax:-</strong></p>



<pre class="wp-block-code"><code><span class="has-inline-color has-vivid-red-color"><strong>fgets(file, length)</strong></span></code></pre>



<pre class="wp-block-preformatted"><strong>Parameters Used:</strong>
The <span class="has-inline-color has-vivid-red-color">fgets()</span> function in PHP accepts two parameters.
<strong>file :</strong> It specifies the file from which characters have to be extracted. 
<strong>length :</strong> It specifies the number of bytes to be read by the <span class="has-inline-color has-vivid-red-color">fgets()</span> function. The default value is 1024 bytes.</pre>



<p class="wp-block-paragraph"><strong>Return Value :</strong> It returns a string of length -1 bytes from the user-specified file, or False if the operation fails.</p>



<p class="wp-block-paragraph"><strong>Errors And Exceptions</strong>:-</p>



<ul class="wp-block-list"><li>Because it reads a single line at a time, the method isn&#8217;t designed for huge files, and reading a long file can take a long time.</li><li>If the <code><span class="has-inline-color has-vivid-red-color"><strong>fgets()</strong></span></code> method is called more than once, the buffer must be emptied.</li><li>Although the <code><span class="has-inline-color has-vivid-red-color"><strong>fgets()</strong></span></code> method returns the Boolean False, it frequently produces a non-Boolean result that evaluates to False.</li></ul>



<h4 class="wp-block-heading">Let&#8217;s take one Example:-</h4>



<p class="wp-block-paragraph">Suppose there is a file named “test.txt” which consists of :</p>



<pre class="wp-block-code"><code>This is the first line.
This is the second line.
This is the third line.</code></pre>



<p class="wp-block-paragraph"><strong>Example 1:-</strong></p>



<script src="https://gist.github.com/AdarshAshwani/305c08ce032ef4148f3cf082977b4587.js"></script>



<p class="wp-block-paragraph"><strong>Output:</strong>&#8211;</p>



<div class="wp-block-image"><figure class="aligncenter size-full is-resized"><img decoding="async" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-107.png" alt="" class="wp-image-7989" width="333" height="52" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-107.png 333w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-107-300x47.png 300w" sizes="(max-width: 333px) 100vw, 333px" /></figure></div>



<p class="wp-block-paragraph"><strong>Example 2:-</strong></p>



<script src="https://gist.github.com/AdarshAshwani/ffe3b4b92e2c548eac1c980d955ded1f.js"></script>



<p class="wp-block-paragraph"><strong>Output:-</strong></p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img decoding="async" width="419" height="105" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-108.png" alt="" class="wp-image-7990" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-108.png 419w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-108-300x75.png 300w" sizes="(max-width: 419px) 100vw, 419px" /></figure></div>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/tutorial-for-fgets-in-reading-file/">Tutorial for fgets() in Reading file</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/tutorial-for-fgets-in-reading-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
