<?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; tip</title>
	<atom:link href="http://www.phpreferencebook.com/tag/tip/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>Quick Tip: getcwd() for Contents of Current Directory</title>
		<link>http://www.phpreferencebook.com/tips/getcwd-scandir-get-display-contents-current-directory/</link>
		<comments>http://www.phpreferencebook.com/tips/getcwd-scandir-get-display-contents-current-directory/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 14:00:52 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[getcwd]]></category>
		<category><![CDATA[scandir]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=352</guid>
		<description><![CDATA[The getcwd() function is short for &#8216;GET Current Working Directory&#8217;. This can easily be combined with the scandir() function which returns an array of all the files and directories inside the specified directory. This tip was excluded from the book as an oversight. &#160; A quick way to get a list of all the contents [...]]]></description>
			<content:encoded><![CDATA[<p>The getcwd() function is short for &#8216;GET Current Working Directory&#8217;. This can easily be combined with the scandir() function which returns an array of all the files and directories inside the specified directory. This tip was excluded from the book as an oversight.<br />
&nbsp;<br />
A quick way to get a list of all the contents of the current directory is to use the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> preprint<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt; pre&gt;'</span><span style="color: #339933;">.</span><span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt; /pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">getcwd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
preprint<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// nicely formatted display of the array</span></pre></div></div>

<p>&nbsp;<br />
Of course, you can skip the print/echo portion if you don&#8217;t wish to display the contents and just use the array to perform other checks, but you get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/getcwd-scandir-get-display-contents-current-directory/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>Sprintf() Tip</title>
		<link>http://www.phpreferencebook.com/tips/sprintf-tip/</link>
		<comments>http://www.phpreferencebook.com/tips/sprintf-tip/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 06:44:39 +0000</pubDate>
		<dc:creator>Mario Lurig</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[precision]]></category>
		<category><![CDATA[sprintf]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.phpreferencebook.com/?p=15</guid>
		<description><![CDATA[From the book: For MySQL security, you can use sprintf() to force user input to have a maximum length and be valid for the structure of your database. Use the precision specifier to automatically parse the string submitted by GET or POST.]]></description>
			<content:encoded><![CDATA[<p>From the book:</p>
<p style="margin-bottom: 0.07in;">
<p style="margin-bottom: 0.07in;"><span style="font-size: small;"><span style="font-family: Palatino Linotype,serif;">For MySQL security, you can use </span><span style="font-family: Palatino Linotype,serif;"><strong>sprintf()</strong></span><span style="font-family: Palatino Linotype,serif;"> to force user input to have a maximum length and be valid for the structure of your database. Use the </span><span style="font-family: Palatino Linotype,serif;"><strong>precision</strong></span><span style="font-family: Palatino Linotype,serif;"><span> specifier to automatically parse the string submitted by GET or POST.</span></span></span></p>
<p style="margin-bottom: 0.07in;"><span style="font-family: Palatino Linotype,serif;"><span style="font-size: x-small;"></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpreferencebook.com/tips/sprintf-tip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
