<?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>SamplePhpCodes.com &#187; fopen</title>
	<atom:link href="http://www.samplephpcodes.com/tag/fopen/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.samplephpcodes.com</link>
	<description>Get PHP Code Help, Sample PHP Scripts,PHP Script Demos</description>
	<lastBuildDate>Mon, 05 Apr 2010 15:39:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating a File In PHP</title>
		<link>http://www.samplephpcodes.com/php-tutorials/php-file-functions/creating-a-file-in-php/</link>
		<comments>http://www.samplephpcodes.com/php-tutorials/php-file-functions/creating-a-file-in-php/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 14:11:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP File Functions]]></category>
		<category><![CDATA[fclose]]></category>
		<category><![CDATA[File Create]]></category>
		<category><![CDATA[fopen]]></category>

		<guid isPermaLink="false">http://samplephpcodes.com/?p=30</guid>
		<description><![CDATA[File Create The fopen function needs two important pieces of information to operate correctly. First, we must supply it with the name of the file that we want it to open. Secondly, we must tell the function what we plan on doing with that file (i.e. read from the file, write information, etc). Since we [...]]]></description>
			<content:encoded><![CDATA[<p><strong>File Create </strong><br />
<strong></strong><br />
The fopen function needs two important pieces of information to operate correctly. First, we must supply it with the name of the file that we want it to open. Secondly, we must tell the function what we plan on doing with that file (i.e. read from the file, write information, etc).<br />
Since we want to create a file, we must supply a file name and tell PHP that we want to write to the file. Note: We have to tell PHP we are writing to the file, otherwise it will not create a new file.<br />
<strong></strong></p>
<pre class="brush: php;">$ourFileName = &quot;testFile.txt&quot;;
$ourFileHandle = fopen($ourFileName, 'w') or die(&quot;can't open file&quot;);
fclose($ourFileHandle);</pre>
<p>The file &#8220;testFile.txt&#8221; should be created in the same directory where this PHP code resides. PHP will see that &#8220;testFile.txt&#8221; does not exist and will create it after running this code. There&#8217;s a lot of information in those three lines of code, let&#8217;s make sure you understand it.<br />
<strong></strong><br />
<strong>1.$ourFileName = &#8220;testFile.txt&#8221;; </strong><br />
<strong></strong><br />
Here we create the name of our file, &#8220;testFile.txt&#8221; and store it into a  PHP String variable $ourFileName.<br />
<strong>2.$ourFileHandle = fopen($ourFileName, &#8216;w&#8217;) or die(&#8220;can&#8217;t open file&#8221;); </strong><br />
This bit of code actually has two parts. First we use the function fopen and give it two arguments: our file name and we inform PHP that we want to write by passing the character &#8220;w&#8221;.<br />
Second, the fopen function returns what is called a file handle, which will allow us to manipulate the file. We save the file handle into the $ourFileHandle variable. We will talk more about file handles later on.<br />
<strong></strong><br />
<strong>1.fclose($ourFileHandle); </strong><br />
<strong></strong><br />
We close the file that was opened. fclose takes the file handle that is to be closed. We will talk more about this more in the file closing lesson.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samplephpcodes.com/php-tutorials/php-file-functions/creating-a-file-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP File Operations In Different Modes</title>
		<link>http://www.samplephpcodes.com/php-tutorials/php-file-functions/php-file-opeartion-in-different-modes/</link>
		<comments>http://www.samplephpcodes.com/php-tutorials/php-file-functions/php-file-opeartion-in-different-modes/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 14:37:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP File Functions]]></category>
		<category><![CDATA[fopen]]></category>
		<category><![CDATA[fopen a]]></category>
		<category><![CDATA[fopen r]]></category>
		<category><![CDATA[fopen w]]></category>
		<category><![CDATA[fopen x]]></category>
		<category><![CDATA[x+.]]></category>

		<guid isPermaLink="false">http://samplephpcodes.com/?p=28</guid>
		<description><![CDATA[File Open A file can be opened using fopen function. Two parameters that must pass to this function are file name and mode. On success fopen returns a file pointer , or FALSE on error. Modes that can be used with fopen are r, r+, w, w+, a, a+, x, x+. Difference between mode &#8216;r&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>File Open </strong><br />
A file can be opened using fopen function. Two parameters that must pass to this function are<br />
 file name and mode. On success fopen returns a file pointer , or  FALSE on error.  Modes that can be used with fopen are  r,  r+,  w, w+,  a,  a+,  x, x+.<br />
            Difference between  mode &#8216;r&#8217; and  &#8216;r+&#8217; :  fopen with mode r open a file for reading, whereas r+ open a file for reading and writing .<br />
	Difference between mode  &#8216;w&#8217; and &#8216;w+&#8217;:  fopen with mode w open a file for writing only, but w+ allows both reading and writing operation.<br />
           Difference between  mode &#8216;a&#8217; and &#8216;a+&#8217;:    fopen with mode &#8216;a&#8217; allow only writing to the file but &#8216;a+&#8217;  permits both reading and writing operation.<br />
	Difference between mode  &#8216;x&#8217; and &#8216;x+&#8217;:  fopen with &#8216;x&#8217;  allows only writing to the file, but &#8216;x+&#8217; permits both reading and writing.<br />
	Main difference between  mode &#8216;w&#8217; and &#8216;a&#8217;:   If the file we are trying to open with mode &#8216;w&#8217; already exist, fopen truncates length  of the file to zero, and write the new content at the beginning of the file.<br />
 If the mode  used to open an already existing file is  &#8216;a&#8217;, new content would be appended  to the end of the file.<br />
            Main difference between  mode &#8216;w&#8217; and &#8216;x&#8217; : both mode open a file for writing only and file pointer points to the beginning of the file ,  difference is  if  the file already exist.   fopen with mode &#8216;x&#8217; returns FALSE if  the file  already exist  whereas fopen with mode &#8216;w&#8217;  truncates  length of the file to zero and write content  at the beginning.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.samplephpcodes.com/php-tutorials/php-file-functions/php-file-opeartion-in-different-modes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
