<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<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/"
	>

<channel>
	<title>PHP-Scripts Blog &#187; PHP 3.x</title>
	<link>http://www.php-scripts.com</link>
	<description>Writing about PHP scripting since 12/99. Learn something new every day.</description>
	<pubDate>Thu, 09 Oct 2008 14:17:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>Using header to redirect the browser</title>
		<link>http://www.php-scripts.com/20050922/24/</link>
		<comments>http://www.php-scripts.com/20050922/24/#comments</comments>
		<pubDate>Fri, 23 Sep 2005 02:16:31 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=24</guid>
		<description><![CDATA[The PHP header function allows redirection of the browser, among other cool things. 
Example redirecting the browser to php-scripts.com homepage:

&#60;?php
header&#40;”Location: http://www.php-scripts.com/”);
?&#62;

]]></description>
			<content:encoded><![CDATA[<p>The PHP header function allows redirection of the browser, among other cool things. </p>
<p>Example redirecting the browser to php-scripts.com homepage:</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<a href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span>”Location: http:<span class="co1">//www.php-scripts.com/”);</span><br />
<span class="kw2">?&gt;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050922/24/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using floor and time to calculate number of days elapsed from UNIX timestamp</title>
		<link>http://www.php-scripts.com/20050921/23/</link>
		<comments>http://www.php-scripts.com/20050921/23/#comments</comments>
		<pubDate>Wed, 21 Sep 2005 20:06:51 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Linux]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<category><![CDATA[Information]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=23</guid>
		<description><![CDATA[Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you&#8217;ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:

&#60;?php
$old_timestamp = 1102971600;
$elapsed_seconds = time&#40;&#41; - $old_timestamp;
print &#8216;Seconds elapsed since [...]]]></description>
			<content:encoded><![CDATA[<p>Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you&#8217;ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<span class="re0">$old_timestamp</span> = <span class="nu0">1102971600</span>;<br />
<span class="re0">$elapsed_seconds</span> = <a href="http://www.php.net/time"><span class="kw3">time</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> - <span class="re0">$old_timestamp</span>;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Seconds elapsed since &#8216;</span> . <a href="http://www.php.net/date"><span class="kw3">date</span></a><span class="br0">&#40;</span><span class="st0">&#8220;m-d-Y H:i:s&#8221;</span>,<span class="re0">$old_timestamp</span><span class="br0">&#41;</span> . <span class="st0">&#8220;: &lt;b&gt;$elapsed_seconds&#8221;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p>Now, let&#8217;s convert those seconds to days using the floor() function, by just adding the following code to the code above:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="coMULTI">/*<br />
divide #seconds by 60 for minutes<br />
divide #of minutes by 60 for hours<br />
divide #of hours by 24 for days<br />
use floor to get integer for day<br />
*/</span><br />
<span class="re0">$elapsed_days</span> = <a href="http://www.php.net/floor"><span class="kw3">floor</span></a><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$elapsed_seconds</span> / <span class="nu0">60</span><span class="br0">&#41;</span> / <span class="nu0">60</span> / <span class="nu0">24</span><span class="br0">&#41;</span>; <br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8220;&lt;br /&gt;Number of days elapsed: $elapsed_days&#8221;</span>;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050921/23/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to join an ID list using IN MySQL function</title>
		<link>http://www.php-scripts.com/20050914/13/</link>
		<comments>http://www.php-scripts.com/20050914/13/#comments</comments>
		<pubDate>Thu, 15 Sep 2005 02:12:21 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[MySQL]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=13</guid>
		<description><![CDATA[How to create a query list of ID numbers using join from an $array and put into a string that can be used in a MySQL query:

$id_numbers = array&#40;1,6,14,32,84,27,49,77&#41;;
$complist = join&#40;”,”, $id_numbers&#41;;
$query = “SELECT id from tablename WHERE id IN&#40;$complist&#41;”;

]]></description>
			<content:encoded><![CDATA[<p>How to create a query list of ID numbers using join from an $array and put into a string that can be used in a MySQL query:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="re0">$id_numbers</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="nu0">1</span>,<span class="nu0">6</span>,<span class="nu0">14</span>,<span class="nu0">32</span>,<span class="nu0">84</span>,<span class="nu0">27</span>,<span class="nu0">49</span>,<span class="nu0">77</span><span class="br0">&#41;</span>;<br />
<span class="re0">$complist</span> = <a href="http://www.php.net/join"><span class="kw3">join</span></a><span class="br0">&#40;</span>”,”, <span class="re0">$id_numbers</span><span class="br0">&#41;</span>;<br />
<span class="re0">$query</span> = “SELECT id from tablename WHERE id IN<span class="br0">&#40;</span><span class="re0">$complist</span><span class="br0">&#41;</span>”;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050914/13/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to strip off last two characters from string using substr</title>
		<link>http://www.php-scripts.com/20050913/5/</link>
		<comments>http://www.php-scripts.com/20050913/5/#comments</comments>
		<pubDate>Tue, 13 Sep 2005 18:54:09 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Language]]></category>

		<category><![CDATA[Functions]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=5</guid>
		<description><![CDATA[substr comes in handy if you need to strip characters off the end of a string.

&#60;?php
$test_string = ‘item 1, item 2, item 3, ‘;
$test_string = substr&#40;$test_string,0,-2&#41;;
echo&#40;$test_string&#41;; // returns “item 1, item 2, item 3″ 
?&#62;

]]></description>
			<content:encoded><![CDATA[<p>substr comes in handy if you need to strip characters off the end of a string.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<span class="re0">$test_string</span> = ‘item <span class="nu0">1</span>, item <span class="nu0">2</span>, item <span class="nu0">3</span>, ‘;<br />
<span class="re0">$test_string</span> = <a href="http://www.php.net/substr"><span class="kw3">substr</span></a><span class="br0">&#40;</span><span class="re0">$test_string</span>,<span class="nu0">0</span>,-<span class="nu0">2</span><span class="br0">&#41;</span>;<br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a><span class="br0">&#40;</span><span class="re0">$test_string</span><span class="br0">&#41;</span>; <span class="co1">// returns “item 1, item 2, item 3″ </span><br />
<span class="kw2">?&gt;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050913/5/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Colorized pretty source code htaccess method</title>
		<link>http://www.php-scripts.com/20050909/11/</link>
		<comments>http://www.php-scripts.com/20050909/11/#comments</comments>
		<pubDate>Sat, 10 Sep 2005 00:12:27 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Installation and configuration]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=11</guid>
		<description><![CDATA[
Tired of black and whit coding that looks like what&#8217;s above? Want to colorize it to look like this instead:

Here is how to make colorized pretty source code using the .htacess method for .phps files:
Step 1. create a text file and save it as .htaccess. Put the following code in the file:

AddType application/x-httpd-php-source .phps

Step 2. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.php-scripts.com/images/2005/highlight_code2.jpg" border="0" ALT="screenshot of non-colorized source code"/></p>
<p>Tired of black and whit coding that looks like what&#8217;s above? Want to colorize it to look like this instead:</p>
<p><img src="http://www.php-scripts.com/images/2005/highlight_code1.jpg" border="0" ALT="screenshot of colorized highlighted source code"/></p>
<p>Here is how to make colorized pretty source code using the .htacess method for .phps files:</p>
<p>Step 1. create a text file and save it as .htaccess. Put the following code in the file:</p>
<div class="codesnip-container" >
<div class="codesnip">AddType application/x-httpd-php-source .phps</div>
</div>
<p>Step 2. change the filename to .phps from .php<br />
Step 3. navigate with your browser to the .phps and voila!</p>
<p>The nice thing about the htacess method is it works with PHP version 3 files, whereas the two function methods only work with version 4.xx and 5.xx. But who is running PHP version 3 any more? Anybody?</p>
<p><b>Other ways to highlight PHP source code</b><br />
If you can&#8217;t or don&#8217;t want to use the htaccess method for some reason then there are a couple PHP functions that will colorize code called: <a href="http://www.php.net/highlight_string">highlight_string()</a> (PHP 4, 5 only) and <a href="http://www.php.net/highlight_file">highlight_file()</a> (PHP 4, 5 only)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050909/11/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to find the location of php.ini on the server</title>
		<link>http://www.php-scripts.com/20050909/8/</link>
		<comments>http://www.php-scripts.com/20050909/8/#comments</comments>
		<pubDate>Fri, 09 Sep 2005 14:50:47 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Functions]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<category><![CDATA[Information]]></category>

		<guid isPermaLink="false">http://www.php-scripts.com/?p=8</guid>
		<description><![CDATA[
Using the phpinfo() function you can easily find the location of the php.ini file on the server. Here&#8217;s the code to generate the phpinfo information pictured above:

&#60;?php
phpinfo&#40;&#41;;
?&#62;

Shown with the red arrows in the screenshot above:
#1 - this is the version of PHP
#2 - these are the configured library. For example &#8216;&#8211;with-mcrypt=/usr/lib&#8217; means the mcrypt library [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.php-scripts.com/images/2005/phpinfo-1.jpg" border="0" ALT="screenshot and description of phpinfo() output"/></p>
<p>Using the phpinfo() function you can easily find the location of the php.ini file on the server. Here&#8217;s the code to generate the phpinfo information pictured above:</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<a href="http://www.php.net/phpinfo"><span class="kw3">phpinfo</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p>Shown with the red arrows in the screenshot above:</p>
<p>#1 - this is the version of PHP<br />
#2 - these are the configured library. For example &#8216;&#8211;with-mcrypt=/usr/lib&#8217; means the mcrypt library is enabled<br />
#3 - <b>the full path location to the php.ini file</b>. In the screenshot above the location is /usr/local/Zend/etc/php.ini</p>
<p>Most likely the php.ini file will be owned by root, so unless you have root you&#8217;ll probably have to ask your hosting company to make changes to this unless you have root.  Also PHP will need to be restarted after changing these settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050909/8/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Hello world!</title>
		<link>http://www.php-scripts.com/20050906/1/</link>
		<comments>http://www.php-scripts.com/20050906/1/#comments</comments>
		<pubDate>Wed, 07 Sep 2005 00:22:16 +0000</pubDate>
		<dc:creator>TDavid</dc:creator>
		
		<category><![CDATA[Language]]></category>

		<category><![CDATA[PHP 5.x]]></category>

		<category><![CDATA[PHP 4.x]]></category>

		<category><![CDATA[PHP 3.x]]></category>

		<guid isPermaLink="false">/?p=1</guid>
		<description><![CDATA[Welcome to the PHP-scripts blog. Though I&#8217;m not a huge fan of &#8216;Hello World&#8217; stuff, it seems that is where most things in the programming world start out. So here we go with examples using print and echo
Hello World using print statement

&#60;?php
print &#8216;Hello World!&#8217;;
?&#62;

Hello World using echo

&#60;?php 
echo &#8216;Hello World!&#8217;; 
?&#62;

What is the difference between [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the PHP-scripts blog. Though I&#8217;m not a huge fan of &#8216;Hello World&#8217; stuff, it seems that is where most things in the programming world start out. So here we go with examples using <a href="http://us2.php.net/print">print</a> and <a href="http://us2.php.net/echo">echo</a></p>
<p><b>Hello World using print statement</b></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Hello World!&#8217;</span>;<br />
<span class="kw2">?&gt;</span></div>
</div>
<p><b>Hello World using echo</b></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php <br />
<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;Hello World!&#8217;</span>; <br />
<span class="kw2">?&gt;</span></div>
</div>
<p>What is the difference between print and echo?  <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40">print behaves like a function</a> and can be used in expressions like this, where echo cannot:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="re0">$returns</span> = <a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8216;Hello World&#8217;</span>; <span class="co1">// $returns = 1 </span><br />
&nbsp;</div>
</div>
<p>echo is a tiny bit faster since it doesn&#8217;t set a return value. </p>
<p><b>Programming tips</b><br />
<i>Pick one format and stick to it</i>. For example, I like to use echo for echoing variable values like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a><span class="br0">&#40;</span><span class="re0">$name</span><span class="br0">&#41;</span>; <span class="co1">// outputs value of string $name </span><br />
&nbsp;</div>
</div>
<p>But I prefer print for mixing text and variables like this:</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="re0">$name</span> = <span class="st0">&#8216;TDavid&#8217;</span>;<br />
<a href="http://www.php.net/print"><span class="kw3">print</span></a> <span class="st0">&#8220;My name is: $name&#8221;</span>; <span class="co1">// outputs: My name is TDavid </span><br />
&nbsp;</div>
</div>
<p>Since you can use or not use parenthesis, it&#8217;s important to determine a style that is consistent throughout coding projects to keep code easy to read.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-scripts.com/20050906/1/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
