<?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>Pep&#039;s Top Blog &#187; PHP</title>
	<atom:link href="http://www.peptop.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peptop.com</link>
	<description>The more we share, the more we have!</description>
	<lastBuildDate>Sun, 10 Jul 2011 09:50:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Study Notes – Storing and Retrieving Data</title>
		<link>http://www.peptop.com/web/php-study-notes-storing-retrieving-data/</link>
		<comments>http://www.peptop.com/web/php-study-notes-storing-retrieving-data/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 14:36:02 +0000</pubDate>
		<dc:creator>Pep</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Study Notes]]></category>

		<guid isPermaLink="false">http://www.peptop.com/?p=141</guid>
		<description><![CDATA[Storing and retrieving data section of the PHP study notes, including reading and writing data via file functions, introduced many useful file functions, such as fopen, fclose, fread, and fwrite, etc.]]></description>
			<content:encoded><![CDATA[<p>Chapter 2 , introduced how to open, read, write, lock, close a file and other useful file functions.<br />
<span id="more-141"></span></p>
<h3>Opening a File</h3>
<h4>Using fopen() to Open a File</h4>
<p>fopen() definition:<br />
<code>resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )</code></p>
<p>fopen() examples:<br />
<code>$handle = fopen("/home/rasmus/file.txt", "r");<br />
$fp = fopen("$_SERVER['DOCUMENT_ROOT']/../orders/orders.txt",'w'); </code></p>
<h4>Summary of File Modes for fopen()</h4>
<table>
<thead>
<tr>
<th>mode</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#8216;r&#8217;</td>
<td>Open for reading only; place the file pointer at the beginning of the file.</td>
</tr>
<tr>
<td>&#8216;r+&#8217;</td>
<td>Open for reading and writing; place the file pointer at the beginning of the file.</td>
</tr>
<tr>
<td>&#8216;w&#8217;</td>
<td>Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;w+&#8217;</td>
<td>Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;a&#8217;</td>
<td>Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;a+&#8217;</td>
<td>Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;x&#8217;</td>
<td>Create and open for writing only; place the file pointer at the beginning of the file.<br />
If the file already exists, the fopen() call will fail by returning FALSE, and PHP will generate a warning.<br />
If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;x+&#8217;</td>
<td>Create and open for reading and writing; place the file pointer at the beginning of the file.<br />
If the file already exists, the fopen() call will fail by returning FALSE, and PHP will generate a warning.<br />
If the file does not exist, attempt to create it.</td>
</tr>
<tr>
<td>&#8216;b&#8217;</td>
<td>Used in conjunction with one of the other modes. Opening file in binary mode, recommend. It is the default mode.</td>
</tr>
<tr>
<td>&#8216;t&#8217;</td>
<td>Used in conjunction with one of the other modes. Opening file in text mode, not recommend.</td>
</tr>
</tbody>
</table>
<h4>Other Points Requiring Attention</h4>
<ul>
<li>You can open files via FTP, HTTP, and other protocols using fopen(). You can disable this capability by turning off the allow_url_fopen directive in the php.ini file.</li>
<li>The scripts must has permission to access the file you are trying to use.</li>
</ul>
<h3>2. Reading and Writing Files</h3>
<h4>Reading from a File</h4>
<p><code>string fgets ( resource $handle [, int $length ] )</code>Gets a line from file pointer.</p>
<p><code>string fgetss ( resource $handle [, int $length [, string $allowable_tags ]] )</code>Identical to fgets(), except that fgetss() attempts to strip any NUL bytes, HTML and PHP tags from the text it reads.</p>
<p><code>array fgetcsv ( resource $handle [, int $length [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape='\\']]]] )</code>Similar to fgets() except that fgetcsv() parses the line it reads for fields in CSV format and returns an array containing the fields read.</p>
<p><code>string fgetc ( resource $handle )</code>Gets a character from the given file pointer.</p>
<p><code>string fread ( resource $handle , int $length )</code>Reads up to length bytes from the file pointer referenced by handle.</p>
<p><code>int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )</code>Reads a file and writes it to the output buffer.</p>
<p><code>int fpassthru ( resource $handle )</code>Reads to EOF on the given file pointer from the current position and writes the results to the output buffer.</p>
<p><code>array file ( string $filename [, int $flags = 0 [, resource $context ]] )</code>Reads an entire file into an array, each element of the array corresponds to a line in the file, with the newline still attached.</p>
<p><code>string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen = -1 ]]]] )</code>This function is similar to file(), except that file_get_contents() returns the file in a string , starting at the specified offset up to maxlen bytes.</p>
<h4>Writing to a File</h4>
<p><code>int fwrite ( resource $handle , string $string [, int $length ] )</code>Writes the contents of string to the file stream pointed to by handle.</p>
<p><code>int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )</code>This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file. If filename does not exist, the file is created. Otherwise, the existing file is overwritten, unless the FILE_APPEND flags is set.</p>
<h4>Navigating Inside a File</h4>
<p><code>bool rewind ( resource $handle )</code>Sets the file position indicator for handle to the beginning of the file stream.</p>
<p><code>int fseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] )</code>Sets the file position indicator for the file referenced by handle. The new position, measured in bytes from the beginning of the file, is obtained by adding offset to the position specified by whence.</p>
<p><code>int ftell ( resource $handle )</code>Returns the position of the file pointer referenced by handle.</p>
<p><code>bool feof ( resource $handle )</code>Tests for end-of-file on a file pointer.</p>
<h3>3. Other Useful File Functions</h3>
<p><code>bool fclose ( resource $handle )</code>The file pointed to by handle is closed.</p>
<p><code>bool file_exists ( string $filename )</code>Checks whether a file or directory exists.</p>
<p><code>int filesize ( string $filename )</code>Gets the size for the given file.</p>
<p><code>bool unlink ( string $filename [, resource $context ] )</code>Deletes filename. There is no function called delete.</p>
<p><code>bool flock ( resource $handle , int $operation [, int &amp;$wouldblock ] )</code>Locks or releases a file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peptop.com/web/php-study-notes-storing-retrieving-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Study Notes &#8211; Crash Course</title>
		<link>http://www.peptop.com/web/php-study-notes-crash-course/</link>
		<comments>http://www.peptop.com/web/php-study-notes-crash-course/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 09:08:15 +0000</pubDate>
		<dc:creator>Pep</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Study Notes]]></category>

		<guid isPermaLink="false">http://www.peptop.com/?p=129</guid>
		<description><![CDATA[Crash course section of the PHP study notes, including the PHP tag styles, comment styles, variables, constants, variable scope, variables related functions, conditional statements, operators, and an overview of precedence.]]></description>
			<content:encoded><![CDATA[<p>Chapter 1 , from a  C/C++ programmer&#8217;s point of view, introduced the PHP basic syntax, variables, constants, variables and constants scope, operator, operator precedence, variable functions, conditional statements, etc for Crash Course.<br />
<span id="more-129"></span></p>
<h3>1. Basic Syntax</h3>
<h4>PHP Tags</h4>
<ul>
<li>XML style (recommended):<br />
<code>&lt;?php echo '&lt;p&gt;Order processed.&lt;/p&gt;'; ?&gt;</code></li>
<li>Short style (need to enable short_open_tag setting):<br />
<code>&lt;? echo '&lt;p&gt;Order processed.&lt;/p&gt;'; ?&gt;</code></li>
<li>Script style:<br />
<code>&lt;script language='php'&gt; echo '&lt;p&gt;Order processed.&lt;/p&gt;'; &lt;/script&gt;</code></li>
<li>ASP style (Need to enable asp_tags setting, not recommended):<br />
<code>&lt;% echo '&lt;p&gt;Order processed.&lt;/p&gt;'; %&gt;</code></li>
</ul>
<h4>Comments</h4>
<ul>
<li>Multiline comments: /*&#8230;*/</li>
<li>single-line comments: //&#8230; or #&#8230;</li>
</ul>
<h3>2. Variables</h3>
<h4>Identifiers Naming Rules</h4>
<ul>
<li>Variables must start with $</li>
<li>Identifiers can be of any length and can consist of letters, numbers, and under-scores</li>
<li>Identifiers cannot begin with a digit</li>
<li>In PHP, identifiers are case sensitive</li>
<li>Function names are not case sensitive, and a variable can have the same name as a function (not make sense enough)</li>
</ul>
<h4>Variable Types</h4>
<p>PHP supports the following basic data types: Integer, Float, String, Boolean, Array, Object.<br />
Two special types are also available: NULL and Resource.</p>
<p>PHP is called weakly typed, or dynamically typed language. So when you needn&#8217;t explicitly specify the type when you declare a variable, PHP changes the variable type according to what is stored in it at any given time. In addition, the variables need not declare a variable before using it.</p>
<h4>Variable Variables</h4>
<p>Variable variables enable you to change the name of a variable dynamically.<br />
<code>$varname = 'tireqty';<br />
$$varname = 5;<br />
This is exactly equivalent to<br />
$tireqty = 5;</code></p>
<h3>3. Constants</h3>
<h4>Declaring Constants</h4>
<p><code>define('USER_NAME', 'admin');<br />
define('IS_ADMIN', TRUE); </code></p>
<h4>Data Type</h4>
<p>Constants can store only boolean, integer, float, or string data.</p>
<h4>Using Constants</h4>
<p>You needn&#8217;t type a &#8220;$&#8221; before a constant name.</p>
<h3>4. Variable and Constant Scope</h3>
<ul>
<li>Built-in superglobal variables are visible everywhere within a script.</li>
<li>Constants, once declared, are always visible globally; that is, they can be used inside and outside functions.</li>
<li>Global variables declared in a script are visible throughout that script, but not inside functions except you declare global refer:<br />
<code>&lt;?php<br />
$a = 1;<br />
$b = 2;<br />
function Sum()<br />
{<br />
global $a, $b;	//global refer<br />
$b = $a + $b;<br />
}<br />
Sum();<br />
echo $b;	//Output result is 3<br />
?&gt;</code></li>
<li>Variables created inside functions are local to the function and cease to exist when the function terminates.</li>
<li>Variables created inside functions and declared as static are invisible from outside the function but keep their value between one execution of the function and the next.</li>
</ul>
<h3>5. Operators</h3>
<h4>Arithmetic Operators</h4>
<p>Including &#8220;+,-,*,/,% (Modulus) &#8220;.</p>
<h4>String Operators</h4>
<p>&#8220;.&#8221;  String concatenation operator adds two strings and generates and stores a result.</p>
<h4>Assignment and Combined Assignment Operators</h4>
<p>Including &#8220;=,+=,-=,*=,/=,%=,.=&#8221;, similar to the C language.</p>
<h4>Self-increment and Self-decrement Operators</h4>
<p>Including &#8220;++,- -&#8221;, like the C language, just understand the difference between $a++ and ++a$.</p>
<h4>Reference Operator</h4>
<p><code>$a = 5;<br />
$b = &amp;$a;<br />
$a = 7; // $a and $b are now both 7<br />
</code></p>
<h4>Comparison Operators</h4>
<p>Including &#8220;==,===,!=,!==,&lt;&gt;,&lt;,&gt;,&lt;=,&gt;=&#8221;.<br />
Note that &#8220;7&#8243; == 7 return TRUE, while 7 === &#8220;7&#8243; returns False, because the identical operator (===), which returns true only if the two operands are both equal and of the same type.</p>
<h4>Logical Operators</h4>
<p>Including &#8220;!, &amp;&amp;, ||, and, or, xor&#8221;, similar to the C language.</p>
<h4>Bitwise Operators</h4>
<p>Including &#8220;~, &amp;, |, ^, &gt;&gt;, &lt;&lt;&#8221;, similar to the C language.</p>
<h4>Other Operators</h4>
<ul>
<li>&#8220;,,new,-&gt;,(?:)&#8221;  similar to the C language.</li>
<li>&#8220;@&#8221; The error suppression operator (@) can be used in front of any expression.</li>
<li>&#8220;` `&#8221; The execution operator is really a pair of operators—a pair of backticks (&#8220;) , PHP attempts to execute whatever is contained between the backticks as a command at the server’s command line.</li>
</ul>
<h3>6. Operator Precedence</h3>
<p>No need to remember precedence and associativity, you can use parentheses when you are uncertain.</p>
<h3>7. Variables and Types Related Functions</h3>
<ul>
<li>string gettype(mixed var); //Returns a string containing the type name</li>
<li>bool settype(mixed var, string type); //change the type of the var</li>
<li>bool is_array(mixed var); //Checks whether the variable is an array</li>
<li>bool  is_long(mixed var); / is_int() / is_integer() //Checks whether the variable is an integer</li>
<li>bool is_double(mixed var); / is_float() / is_real() //Checks whether the variable is a float</li>
<li>bool is_scalar(mixed var); //Checks whether the variable is a scalar, that is, an integer, boolean, string, or float</li>
<li>bool is_callable(mixed var); //Checks whether the variable is the name of a valid function</li>
<li>There are similar functions like is_string(), is_bool(), is_object(), is_resource(), is_null() etc.</li>
<li>bool isset ( mixed var [, mixed var [, ...]]); //Returns true if it exists and false otherwise</li>
<li>void unset ( mixed var [, mixed var [, ...]]); //Gets rid of the variable it is passed</li>
<li>bool empty ( mixed var [, mixed var [, ...]]); //Checks to see whether a variable exists and has a nonempty, nonzero value</li>
</ul>
<h3>8. Conditional statements</h3>
<ul>
<li>if/elseif/else</li>
<li>switch</li>
<li>while/do&#8230;while</li>
<li>for/foreach</li>
<li>break</li>
</ul>
<p>All these conditional and loop statements are similar to other programming languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peptop.com/web/php-study-notes-crash-course/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Study Notes</title>
		<link>http://www.peptop.com/web/php-study-notes/</link>
		<comments>http://www.peptop.com/web/php-study-notes/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 08:37:59 +0000</pubDate>
		<dc:creator>Pep</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Study Notes]]></category>

		<guid isPermaLink="false">http://www.peptop.com/?p=125</guid>
		<description><![CDATA[Include introduction of "PHP and MySQL Web Development 4th Edition" and the directory of  PHP study notes.]]></description>
			<content:encoded><![CDATA[<p>For PHP, I can read it, modify it, but can not write it, after the World Cup, I intend to make a systematic study of PHP.<br />
The reference book is &#8220;PHP and MySQL Web Development 4th Edition&#8221; written by Luke Welling and Laura Thomson, this book is known as  &#8220;PHP Bible&#8221; .</p>
<p>As usual, the book briefly introduced what is PHP, MySQL, Why use PHP / MySQL, as well as their strengths and so on, quickly scanned.</p>
<p>Followed by What is new in PHP5:</p>
<ul>
<li> Better object-oriented support built around a completely new object model</li>
<li> Exceptions for scalable, maintainable error and exception handling </li>
<li> built-in SimpleXML for easy handling of XML data </li>
</ul>
<p>And key features of PHP 5.3 (At the time of writing, PHP 5.2 was the current version) for example, namespaces (very important) and so on.<span id="more-125"></span></p>
<h3> Directory of PHP Study Notes </h3>
<ol>
<li> <a href="/web/php-study-notes-crash-course/">PHP Crash Course</a> </li>
<li> <a href="/web/php-study-notes-storing-retrieving-data/">Storing and Retrieving Data</a> </li>
<li> Using Arrays </li>
<li> String Manipulation and Regular Expressions </li>
<li> Reusing Code and Writing Functions</li>
<li> Object-Oriented PHP </li>
<li> Error and Exception Handling </li>
<li> &#8230;&#8230;</li>
<li> To be added </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.peptop.com/web/php-study-notes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

