<?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>PHP Reference Book Blog &#187; functions</title>
	<atom:link href="http://www.phpreferencebook.com/tag/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpreferencebook.com</link>
	<description>PHP Reference: Beginner to Intermediate PHP5</description>
	<lastBuildDate>Wed, 25 Aug 2010 12:58:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>fwrite() has a Double Tip that is Misplaced</title>
		<link>http://www.phpreferencebook.com/corrections/fwrite-double-tip-misplaced/</link>
		<comments>http://www.phpreferencebook.com/corrections/fwrite-double-tip-misplaced/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 12:00:09 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Corrections]]></category>
		<category><![CDATA[fread]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[fwrite]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=346</guid>
		<description><![CDATA[On page 131, the fwrite() function has a TIP that reads: &#160; To read the entire file into a string, use the function filesize(). // file.txt contains the sentence: Hello World! $filename = 'file.txt'; $file = fopen&#40;$filename, 'r'&#41;; $string = fread&#40; $file, filesize&#40;$filename&#41; &#41;; var_dump&#40;$string&#41;; // file.txt now contains at the end: Hello World! You&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>On page 131, the fwrite() function has a TIP that reads:<br />
&nbsp;<br />
<strong>To read the entire file into a string, use the function filesize().</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// file.txt contains the sentence: Hello World!</span>
<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'file.txt'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// file.txt now contains at the end: Hello World!</span></pre></div></div>

<p>You&#8217;ll notice that this is the same tip as fread() and doesn&#8217;t belong. It should be considered &#8216;removed&#8217;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/corrections/fwrite-double-tip-misplaced/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &amp; Ampersand: Passing by Reference</title>
		<link>http://www.phpreferencebook.com/samples/php-pass-by-reference/</link>
		<comments>http://www.phpreferencebook.com/samples/php-pass-by-reference/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 00:04:25 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Samples]]></category>
		<category><![CDATA[ampersand]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=165</guid>
		<description><![CDATA[The following PHP Reference excerpt is from pages 20-21. &#38; &#8211; Pass by Reference References allow two variables to refer to the same content. In other words, a variable points to its content (rather than becoming that content). Passing by reference allows two variables to point to the same content under different names. The ampersand [...]]]></description>
			<content:encoded><![CDATA[<p>The following <a href="http://www.phpreferencebook.com/">PHP Reference</a> excerpt is from pages 20-21.</p>
<p style="background: #000000 none repeat scroll 0% 0%; margin-bottom: 0.07in;" lang="en-US"><span style="color: #ffffff;"><span style="font-family: Palatino Linotype,serif;">&amp; &#8211; Pass by Reference</span></span></p>
<p style="margin-bottom: 0.07in;" lang="en-US"><span style="color: #000000;"><span style="font-family: Palatino Linotype,serif;">References allow two variables to refer to the same content. In other words, a variable points to its content (rather than becoming that content). Passing by reference allows two variables to point to the same content under different names. The ampersand ( &amp; ) is placed before the variable to be referenced.</span></span></p>
<p style="margin-bottom: 0.07in;" lang="en-US"><span style="color: #000000;"><span style="font-family: Palatino Linotype,serif;"><em>Examples:</em></span></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// $b references the same value as $a, currently 1</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$b</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1 is added to $b, which effects $a the same way</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;b is equal to <span style="color: #006699; font-weight: bold;">$b</span>, and a is equal to <span style="color: #006699; font-weight: bold;">$a</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<pre style="background: #c0c0c0 none repeat scroll 0% 0%; margin-bottom: 0.07in; font-style: normal;" lang="en-US"><span style="color: #000000;"><span style="font-family: Courier New,monospace;">b is equal to 2, and a is equal to 2</span></span></pre>
<p style="margin-bottom: 0.07in;" align="center"><span style="font-family: Symbol;"></span></p>
<p style="margin-bottom: 0.07in;" lang="en-US"><span style="color: #000000;"><span style="font-family: Palatino Linotype,serif;">Use this for functions when you wish to simply alter the original variable and return it again to the same variable name with its new value assigned.</span></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> add<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// The &amp;amp; is before the argument $var</span>
<span style="color: #000088;">$var</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
add<span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;a is <span style="color: #006699; font-weight: bold;">$a</span>,&quot;</span><span style="color: #339933;">;</span>
add<span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; a is <span style="color: #006699; font-weight: bold;">$a</span>, and b is <span style="color: #006699; font-weight: bold;">$b</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Note: $a and $b are NOT referenced</span></pre></div></div>

<pre style="background: #c0c0c0 none repeat scroll 0% 0%; margin-bottom: 0.07in;">a is 2, a is 2, and b is 11</pre>
<p style="margin-bottom: 0.07in;" lang="en-US"><span style="color: #000000;"><span style="font-family: Palatino Linotype,serif;">You can also do this to alter an array with foreach:</span></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span> <span style="color: #b1b100;">as</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">unset</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Must be included, $value remains after foreach loop</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<pre style="background: #c0c0c0 none repeat scroll 0% 0%; margin-bottom: 0.07in;">Array ( [0] =&gt; 11 [1] =&gt; 12 [2] =&gt; 13 [3] =&gt; 14 )</pre>
<p>
<hr width='50%' />
<p>What tricks do you have for using the ampersand in PHP to pass by reference?<br />
Leave them in the comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/samples/php-pass-by-reference/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>array_key_exists() Function Index Correction</title>
		<link>http://www.phpreferencebook.com/corrections/array_key_exists-function-index/</link>
		<comments>http://www.phpreferencebook.com/corrections/array_key_exists-function-index/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 03:38:43 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Corrections]]></category>
		<category><![CDATA[array_key_exists]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[index]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=101</guid>
		<description><![CDATA[Thanks to John for submitting this correction! In the Function Index (pg. 161), array_key_exists() is listed as page 82. However, it is actually on page 79. Feel free to submit a correction yourself if you find any!]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.phpreferencebook.com/corrections/comment-page-1/#comment-37">John</a> for submitting this <a href="http://www.phpreferencebook.com/category/corrections/">correction</a>!</p>
<p>In the Function Index (pg. 161), array_key_exists() is listed as page 82. However, it is actually on page 79.</p>
<p>Feel free to <a href="http://www.phpreferencebook.com/corrections/">submit a correction</a> yourself if you find any!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/corrections/array_key_exists-function-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strip_tags() &#8211; Less Than you Bargained For</title>
		<link>http://www.phpreferencebook.com/tips/strip_tags/</link>
		<comments>http://www.phpreferencebook.com/tips/strip_tags/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 22:04:40 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[greater than]]></category>
		<category><![CDATA[htmlspecialchars]]></category>
		<category><![CDATA[less than]]></category>
		<category><![CDATA[strip_tags]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=19</guid>
		<description><![CDATA[While this may be handy for removing HTML from a string, be forewarned that the function is a lot less picky than you may think when it comes to the less than symbol ( &#60; ). First, the section from the PHP book: strip_tags($string [, allowed_tags]) allowed_tags – [optional] $string Remove HTML tags and comments [...]]]></description>
			<content:encoded><![CDATA[<p>While this may be handy for removing HTML from a string, be forewarned that the function is a lot less picky than you may think when it comes to the less than symbol ( &lt; ). First, the section from the <a href="http://www.phpreferencebook.com/purchase/">PHP book</a>:</p>
<hr /><strong>strip_tags($string [, <em>allowed_tags</em>])</strong></p>
<p><em>allowed_tags </em>– [optional] $string</p>
<p>Remove HTML tags and comments from $string. If specific tags should be<br />
excluded, they can be specified inside allowed_tags.</p>
<p>Examples:<br />
<code>$string = "&lt;p&gt;This is a paragraph. &lt;/p&gt;&lt;strong&gt;Yay!&lt;/strong&gt;";<br />
echo strip_tags($string), strip_tags($string, '&lt;p&gt;');</code></p>
<p>HTML Source Code:</p>
<p><code>This is a paragraph. Yay! &lt;p&gt;This is a paragraph. &lt;/p&gt;Yay!</code></p>
<hr />So what happens to the following example, when we want to remove all the tags? Fair warning, something strange happens:</p>
<p><code>$string = "I &lt;strong&gt;love&lt;/strong&gt; this book because it costs &lt;$20.";<br />
echo strip_tags($string);</code></p>
<p>HTML Source Code:</p>
<p><code>I love this book because it costs</code></p>
<p>As you can see, it removed the &lt;$20 portion of the string as well, even without the closing greater than ( &gt; ) tag at the end. Be careful when using <strong>strip_tags()</strong>, especially without specifying the <em>allowed tags</em>, or consider using an alternate such as <strong>htmlspecialchars()</strong> to encode the characters into their html equivalent rather than removing them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/strip_tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
