<?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 Software Developing</title>
	<atom:link href="http://www.phpdeveloping.co.za/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Closing PHP tags are optional</title>
		<link>http://www.phpdeveloping.co.za/syntax/closing-php-tags-are-optional.html</link>
		<comments>http://www.phpdeveloping.co.za/syntax/closing-php-tags-are-optional.html#comments</comments>
		<pubDate>Tue, 29 Sep 2009 15:38:14 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Syntax]]></category>
		<category><![CDATA[closing tag]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=138</guid>
		<description><![CDATA[Sometimes leaving out the closing PHP tags ( ?> ) are better because it prevents errors due to unwanted whitespace at the end of your script.   This is especially useful if you&#8217;re including various PHP files.
]]></description>
			<content:encoded><![CDATA[<p>Sometimes leaving out the closing PHP tags ( ?> ) are better because it prevents errors due to unwanted whitespace at the end of your script.   This is especially useful if you&#8217;re including various PHP files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/syntax/closing-php-tags-are-optional.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downloading PDF files</title>
		<link>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html</link>
		<comments>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html#comments</comments>
		<pubDate>Thu, 10 Sep 2009 05:45:47 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Download]]></category>
		<category><![CDATA[cURL]]></category>
		<category><![CDATA[pdf]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=135</guid>
		<description><![CDATA[If you&#8217;ve done the Thirty Day Challenge, you&#8217;ll know how tedious it can be to download all the PDF files.  Norio created a cool downloading script that saved me a lot of time.  I was just too lazy to sit and write something like it, so I&#8217;m stealing his!

&#60;?php
// make sure our download [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve done the <a href="http://www.thirtydaychallenge.com">Thirty Day Challenge</a>, you&#8217;ll know how tedious it can be to download all the PDF files.  <a href="http://www.norio.co.za">Norio</a> created a cool downloading script that saved me a lot of time.  I was just too lazy to sit and write something like it, so I&#8217;m stealing his!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// make sure our download doesn't time out or get interrupted by closing the browser</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ignore_user_abort</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// destination to download to</span>
<span style="color: #000088;">$file_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sites/default/files/30dc&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// create the destination directory if it doesn't exist</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// go through each day of training (1-31)</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">31</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// download the HTML contents of the training page for that day</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.thirtydaychallenge.com/training/2009day&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #009933; font-weight: bold;">%02d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// provide some feedback on where we are</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;Day <span style="color: #006699; font-weight: bold;">$i</span>:&lt;/b&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// flush output to browser - see php.net/flush</span>
    <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// directory to download the current day's PDFs to</span>
    <span style="color: #000088;">$daydir</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file_dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/day<span style="color: #006699; font-weight: bold;">$i</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// create the directory if it doesn't exist</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$daydir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">mkdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$daydir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// grab all the URLs to the PDFs (regular expressions are awesome!)</span>
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'~(http://media.thirtydaychallenge.com.s3.amazonaws.com/training09/([0-9A-Za-z_]+.pdf))~'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// go through each url we grabbed above</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// check if the file already exists (no use in re-downloading PDFs we have)</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// provide some feedback on where we are</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Downloading {<span style="color: #006699; font-weight: bold;">$matches[2]</span>[<span style="color: #006699; font-weight: bold;">$key</span>]}.&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// flush output to browser</span>
        <span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// download the pdf and store it locally</span>
        <span style="color: #990000;">file_put_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$daydir}</span>/{<span style="color: #006699; font-weight: bold;">$matches[2]</span>[<span style="color: #006699; font-weight: bold;">$key</span>]}&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a target=_blank href="http://php.boff.co.za/quick-pdf-downloading-script-done-php">Check out the full post at Boff.co.za</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/download/downloading-pdf-files.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date and Strtotime Coolness</title>
		<link>http://www.phpdeveloping.co.za/dates/date-and-strtotime-coolness.html</link>
		<comments>http://www.phpdeveloping.co.za/dates/date-and-strtotime-coolness.html#comments</comments>
		<pubDate>Fri, 04 Sep 2009 12:44:14 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Dates]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[strtotime]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=133</guid>
		<description><![CDATA[Two very useful functions in PHP is strtotime and date.  It can be cumbersome to make use of these 2 though, so I got a little function that makes it so much easier.

function odate&#40;$format, $criteria&#41;&#123;
  return &#40;date&#40;$format&#41;, strtotime&#40;$criteria, strtotime&#40;$format&#41;&#41;&#41;;
&#125;

Now all you do is call it like :

echo odate&#40;&#34;Y-m-d H:i:s&#34;, &#34;+1 days&#34;&#41;; // 1 [...]]]></description>
			<content:encoded><![CDATA[<p>Two very useful functions in PHP is strtotime and date.  It can be cumbersome to make use of these 2 though, so I got a little function that makes it so much easier.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> odate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$format</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$format</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now all you do is call it like :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> odate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;+1 days&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1 day ahead of today</span>
<span style="color: #b1b100;">echo</span> odate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-7 days&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//  7 days ago</span>
<span style="color: #b1b100;">echo</span> odate<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d H:i:s&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;+1 hours&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 1 hours from now</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/dates/date-and-strtotime-coolness.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting information from a URL</title>
		<link>http://www.phpdeveloping.co.za/url/getting-information-from-a-url.html</link>
		<comments>http://www.phpdeveloping.co.za/url/getting-information-from-a-url.html#comments</comments>
		<pubDate>Fri, 14 Aug 2009 07:51:17 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[URL]]></category>
		<category><![CDATA[parse_url]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=131</guid>
		<description><![CDATA[Very often you need to be able to pull out parts of the information that is contained within a URL.  Like the port, the protocol, etc.
This is where the parse_url function is so handy.  
Let&#8217;s look at the following code:

  $url_info = parse_url&#40;'http://username:password@www.phpdeveloping.co.za:80/directory/?arg=value#anchor'&#41;;  
  print_r&#40;$url_info&#41;;

The output will be something like:

Array [...]]]></description>
			<content:encoded><![CDATA[<p>Very often you need to be able to pull out parts of the information that is contained within a URL.  Like the port, the protocol, etc.</p>
<p>This is where the <a href="http://www.php.net/manual/en/function.parse-url.php">parse_url</a> function is so handy.  </p>
<p>Let&#8217;s look at the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$url_info</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://username:password@www.phpdeveloping.co.za:80/directory/?arg=value#anchor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  <span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url_info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The output will be something like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">Array</span>  
<span style="color: #009900;">&#40;</span>  
  <span style="color: #009900;">&#91;</span>scheme<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> http  
  <span style="color: #009900;">&#91;</span>host<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> www<span style="color: #339933;">.</span>phpdeveloping<span style="color: #339933;">.</span>co<span style="color: #339933;">.</span>za 
  <span style="color: #009900;">&#91;</span>user<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> username  
  <span style="color: #009900;">&#91;</span>pass<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> password  
  <span style="color: #009900;">&#91;</span>path<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">/</span>directory  
  <span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">/</span><span style="color: #cc66cc;">80</span>  
  <span style="color: #009900;">&#91;</span>query<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> arg<span style="color: #339933;">=</span>value  
  <span style="color: #009900;">&#91;</span>fragment<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> anchor  
<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/url/getting-information-from-a-url.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Posting a Tweet to Twitter using PHP</title>
		<link>http://www.phpdeveloping.co.za/twitter/posting-a-tweet-to-twitter-using-php.html</link>
		<comments>http://www.phpdeveloping.co.za/twitter/posting-a-tweet-to-twitter-using-php.html#comments</comments>
		<pubDate>Thu, 13 Aug 2009 07:11:17 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=129</guid>
		<description><![CDATA[I found this PHP Twitter Class after having recently started developing my own class.  I&#8217;d recommend downloading this if you&#8217;re looking to do anything with PHP and Twitter because it takes care of most of the work for you.
If you want to post a Tweet to Twitter, it&#8217;s as simple as the following lines [...]]]></description>
			<content:encoded><![CDATA[<p>I found this <a href="http://classes.verkoyen.eu/twitter/">PHP Twitter Class</a> after having recently started developing my own class.  I&#8217;d recommend downloading this if you&#8217;re looking to do anything with PHP and Twitter because it takes care of most of the work for you.</p>
<p>If you want to post a Tweet to Twitter, it&#8217;s as simple as the following lines of code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span> <span style="color: #0000ff;">&quot;twitter.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Twitter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$t</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">updateStatus</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a Tweet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now doesn&#8217;t that make life a lot easier?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/twitter/posting-a-tweet-to-twitter-using-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How long does your script run?</title>
		<link>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html</link>
		<comments>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html#comments</comments>
		<pubDate>Wed, 12 Aug 2009 19:51:48 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[load speed]]></category>
		<category><![CDATA[running time]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=127</guid>
		<description><![CDATA[A while back I launched WebSpeedTest.co.za which is just a little script to check how long it takes to load your website.  It doesn&#8217;t take into account loading of all objects on the website, just the HTML.
Some of the code can be used in your PHP script to see how long it takes to [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I launched <a href="http://www.webspeedtest.co.za/">WebSpeedTest.co.za</a> which is just a little script to check how long it takes to load your website.  It doesn&#8217;t take into account loading of all objects on the website, just the HTML.</p>
<p>Some of the code can be used in your PHP script to see how long it takes to load.</p>
<p>First what you do is add this at the very top of your script.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span></pre></div></div>

<p>That will have recorded your start time in the variable $start.</p>
<p>Now, at the very end of your script add this in:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$finish</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$total_time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$finish</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>$total_time now contains the amount of seconds it took to run your script.  This can be useful for debugging to check where you might have bottlenecks.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/performance/how-long-does-your-script-run.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smarty quick and dirty</title>
		<link>http://www.phpdeveloping.co.za/templates/smarty-quick-and-dirty.html</link>
		<comments>http://www.phpdeveloping.co.za/templates/smarty-quick-and-dirty.html#comments</comments>
		<pubDate>Wed, 12 Aug 2009 19:44:56 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Templates]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=125</guid>
		<description><![CDATA[Smarty is an excellent template system used for PHP.  It&#8217;s definitely the best and most versatile one I&#8217;ve seen.
Let&#8217;s say you have an index.tpl (the default template file extension in Smarty) with the following in it:

&#60;html&#62;
&#60;head&#62;
&#60;title&#62;Information&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
Number 1: {$num1}&#60;br&#62;
Number 2: {$num2}&#60;br&#62;
&#60;/body&#62;
&#60;/html&#62;

Now, to actually use the template you would have code like the following:

$smarty = new [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.smarty.net/">Smarty</a> is an excellent template system used for PHP.  It&#8217;s definitely the best and most versatile one I&#8217;ve seen.</p>
<p>Let&#8217;s say you have an index.tpl (the default template file extension in Smarty) with the following in it:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
Number 1: {$num1}&lt;br&gt;
Number 2: {$num2}&lt;br&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Now, to actually use the template you would have code like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$smarty</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Smarty<span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'num1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'111'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'num2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'222'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$smarty</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As simple as that!</p>
<p>The output would be:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Information&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
Number 1: 111&lt;br&gt;
Number 2: 222&lt;br&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>That is just a simple example, and there are a lot more advanced things you can do with it.  Check out the <a href="http://www.smarty.net/crashcourse.php">Smarty Crash Course</a> for some ideas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/templates/smarty-quick-and-dirty.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Eval</title>
		<link>http://www.phpdeveloping.co.za/strings/using-eval.html</link>
		<comments>http://www.phpdeveloping.co.za/strings/using-eval.html#comments</comments>
		<pubDate>Tue, 11 Aug 2009 10:34:30 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=123</guid>
		<description><![CDATA[I use this function very rarely.  For some reason I just never need to use it.  I know in Drupal it is used quite often, especially if you use the PHP input field for a node.  This allows you to enter PHP code that will be evaluated (or run) and then the [...]]]></description>
			<content:encoded><![CDATA[<p>I use this function very rarely.  For some reason I just never need to use it.  I know in Drupal it is used quite often, especially if you use the PHP input field for a node.  This allows you to enter PHP code that will be evaluated (or run) and then the output is shown as the node&#8217;s content.</p>
<p>I suppose this is mostly used when you want a user to be able to enter PHP code into a text field and then run it.  Not always too secure I would think, so be careful where and how you use this.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  $s = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">phpinfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;;
  eval($s);</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/strings/using-eval.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Decimal to Roman numbers</title>
		<link>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html</link>
		<comments>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:37:21 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Numbers]]></category>
		<category><![CDATA[roman numbers]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=121</guid>
		<description><![CDATA[I needed a function to translate from decimal numbers to their Roman number equivalent.  Here&#8217;s a handy little function I found.

private function numberToRoman&#40;$num&#41;
&#123;
     $n = intval&#40;$num&#41;;
     $result = '';
&#160;
     $lookup = array&#40;'M' =&#62; 1000, 'CM' =&#62; 900, 'D' =&#62; 500, 'CD' =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a function to translate from decimal numbers to their Roman number equivalent.  Here&#8217;s a handy little function I found.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> numberToRoman<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$lookup</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'M'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'CM'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">900</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'D'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'CD'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'C'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'XC'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'L'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'XL'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'X'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IX'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'V'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IV'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lookup</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$roman</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$matches</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$n</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$roman</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple HTML DOM Parser &#8211; All images on a website</title>
		<link>http://www.phpdeveloping.co.za/uncategorized/simple-html-dom-parser-all-images-on-a-website.html</link>
		<comments>http://www.phpdeveloping.co.za/uncategorized/simple-html-dom-parser-all-images-on-a-website.html#comments</comments>
		<pubDate>Mon, 03 Aug 2009 06:30:39 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=119</guid>
		<description><![CDATA[Following my post on getting links on a website, I thought I&#8217;ll also show you how to use those functions to get all the images on a website.

  $url = &#34;http://www.phpdeveloping.co.za/&#34;;
  $html = file_get_html&#40;$url&#41;;
  if &#40;$images = $html-&#62;find&#40;'img'&#41;&#41;
  &#123;
    foreach&#40;$images as $image&#41;
    &#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p>Following my post on getting <a href=parsing/simple-html-dom-parser-links-on-a-website.html>links on a website</a>, I thought I&#8217;ll also show you how to use those functions to get all the images on a website.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.phpdeveloping.co.za/&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> file_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$images</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$image</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>You can see how this makes your life a little bit easier when you compare it to <a href=/regular-expression/find-images-in-a-html-document.html>the function I always use</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/uncategorized/simple-html-dom-parser-all-images-on-a-website.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
