<?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>itlivewire dev blog &#187; php</title>
	<atom:link href="http://itlivewire.com/devblog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://itlivewire.com/devblog</link>
	<description>Just another web development blog...</description>
	<lastBuildDate>Mon, 16 Apr 2012 12:37:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>hypenate function</title>
		<link>http://itlivewire.com/devblog/2011/01/16/hypenate-function/</link>
		<comments>http://itlivewire.com/devblog/2011/01/16/hypenate-function/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 10:37:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=385</guid>
		<description><![CDATA[The hypenated function helps you make a hypenated string. It replaces the spaces with a hypen (-), good for SEO and clean url string. Example: &#8220;Room nr IT Park and Country Mall&#8221; Becomes: &#8220;Room-nr-IT-Park-and-Country Mall&#8221; function hypenate($url){ $patterns[0]= &#34;/,/&#34;; $replacements[0]=&#34;&#34;; $patterns[1]=&#34;/\s\s+/&#34;; $replacements[1]=&#34;-&#34;; $url = preg_replace($patterns,$replacements,$url); return $url; } Usage in PHP hypenate(&#34;The quick brown fox&#34;); [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>hypenated</strong> function helps you make a <strong>hypenated string</strong>. </p>
<p>It replaces the spaces with a <strong>hypen (-)</strong>, good for SEO and clean url string.<br />
Example: &#8220;Room nr IT Park and Country Mall&#8221;<br />
Becomes: &#8220;Room-nr-IT-Park-and-Country Mall&#8221;</p>
<pre class="brush: php;">
function hypenate($url){
        $patterns[0]= &quot;/,/&quot;;
        $replacements[0]=&quot;&quot;;
        $patterns[1]=&quot;/\s\s+/&quot;;
        $replacements[1]=&quot;-&quot;;
        $url = preg_replace($patterns,$replacements,$url);
        return $url;
}
</pre>
<p>Usage in PHP</p>
<pre class="brush: php;">hypenate(&quot;The quick brown fox&quot;);</pre>
<p>output: The-quick-brown-fox</p>
<p>It can also remove out specific string you don&#8217;t want to show up on your url e.g. a <strong>comma &#8220;,&#8221;</strong>  just specify it on the <strong>patterns[0] array</strong> in regular expression form</p>
<pre class="brush: php;"> $patterns[0]= &quot;/,/&quot;;</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2011/01/16/hypenate-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the clients IP Address in PHP</title>
		<link>http://itlivewire.com/devblog/2010/11/03/get-the-clients-ip-address-in-php/</link>
		<comments>http://itlivewire.com/devblog/2010/11/03/get-the-clients-ip-address-in-php/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 05:38:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[php ipaddress]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/2010/11/03/get-the-clients-ip-address-in-php/</guid>
		<description><![CDATA[This function will get the client&#8217;s IP adress function getClientIP(){ if (!$_SERVER['HTTP_CLIENT_IP']) $ip = $_SERVER['REMOTE_ADDR'] else $ip =$_SERVER['HTTP_CLIENT_IP']; return $ip; }]]></description>
			<content:encoded><![CDATA[<p>This function will get the client&#8217;s IP adress</p>
<pre class="brush: php;">
function getClientIP(){

    if (!$_SERVER['HTTP_CLIENT_IP'])
         $ip = $_SERVER['REMOTE_ADDR']
    else
        $ip =$_SERVER['HTTP_CLIENT_IP'];
    return $ip;

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2010/11/03/get-the-clients-ip-address-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>codeigniter upload &#8220;The filetype you are attempting to upload is not allowed&#8221;</title>
		<link>http://itlivewire.com/devblog/2010/04/13/codeigniter-upload-the-filetype-you-are-attempting-to-upload-is-not-allowed/</link>
		<comments>http://itlivewire.com/devblog/2010/04/13/codeigniter-upload-the-filetype-you-are-attempting-to-upload-is-not-allowed/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 02:36:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=353</guid>
		<description><![CDATA[Error when uploading your file using codeigniter upload &#8220;The filetype you are attempting to upload is not allowed&#8221; Causes: 1. Invalid file type uploaded by the user your uploading (.doc when only .xls is allowed) 2. The file uploaded is not within the specified file types added in the upload config 3. Mime type error [...]]]></description>
			<content:encoded><![CDATA[<p>Error when uploading your file using codeigniter upload<br />
<strong>&#8220;The filetype you are attempting to upload is not allowed&#8221;</strong></p>
<p>Causes:</p>
<p>1. Invalid file type uploaded by the user your uploading (.doc when only .xls is allowed)<br />
2. The file uploaded is not within the specified file types added in the upload config<br />
3. Mime type error in codeigniter caused by the mime type of the extension does not match the mime type specified in <strong>/application/config/mimes.php</strong></p>
<p>Start by checking what is the mime type of the file your uploading </p>
<pre class="brush: php;">
$data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
$mimetype= $data['upload_data']['file_type'];
echo $mimetype;
</pre>
<p>then check in the mimes.php if that mime type matches the extension you want to upload</p>
<p>Example:<br />
word document</p>
<pre class="brush: php;">'doc'	=&gt;	'application/msword'</pre>
<p>excel file has many mime types, if its missing just add it in the array</p>
<pre class="brush: php;">'xls'	=&gt;	array('application/excel', 'application/vnd.ms-excel','application/x-msexcel')</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2010/04/13/codeigniter-upload-the-filetype-you-are-attempting-to-upload-is-not-allowed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP file stream</title>
		<link>http://itlivewire.com/devblog/2010/02/19/php-file-stream/</link>
		<comments>http://itlivewire.com/devblog/2010/02/19/php-file-stream/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 06:48:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/2010/02/19/php-file-stream/</guid>
		<description><![CDATA[The code below shows how to open a file from the server which cannot be accessed by the web server $path = &#34;/home/files/documents.doc&#34;; header(&#34;Cache-Control: pre-check=0, post-check=0, max-age=0&#34;); header('Content-Type: application/octet-stream'); header(&#34;Content-Disposition: attachment; filename=documents.doc); header(&#34;Content-Description: File Transfer&#34;); header(&#34;Content-Type:documents.doc); header(&#34;Last-Modified: &#34; . now()); echo readfile($path);]]></description>
			<content:encoded><![CDATA[<p>The code below shows how to open a file from the server which cannot be accessed by the web server</p>
<pre class="brush: php;">
$path = &quot;/home/files/documents.doc&quot;;
   header(&quot;Cache-Control: pre-check=0, post-check=0, max-age=0&quot;);
   header('Content-Type: application/octet-stream');
   header(&quot;Content-Disposition: attachment; filename=documents.doc);
   header(&quot;Content-Description: File Transfer&quot;);
   header(&quot;Content-Type:documents.doc);
   header(&quot;Last-Modified: &quot; . now());
echo readfile($path);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2010/02/19/php-file-stream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mt_rand</title>
		<link>http://itlivewire.com/devblog/2010/01/25/mt_rand/</link>
		<comments>http://itlivewire.com/devblog/2010/01/25/mt_rand/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 11:25:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/2010/01/25/mt_rand/</guid>
		<description><![CDATA[The mt_rand() function is a drop-in replacement for rand(). It uses a random number generator with known characteristics using the Mersenne Twister from the php docs website I somehow noticed php rand() has a pattern, So I dug up the php docs for a better rand function and end up discovering this neat random function [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>mt_rand()</strong> function is a drop-in replacement for rand().<br />
It uses a <strong>random number generator</strong> with known characteristics using the Mersenne Twister from the <a href="http://php.net/manual/en/function.mt-rand.php">php docs </a>website</p>
<p>I somehow noticed php rand() has a pattern, So I dug up the php docs for a better rand function and end up discovering this neat random function</p>
<p><strong>Use mt_rand()</strong></p>
<pre class="brush: php;">&lt;?php
echo mt_rand() . &quot;\n&quot;;
echo mt_rand() . &quot;\n&quot;;

echo mt_rand(5, 15);

?&gt;</pre>
<p><strong>Output</strong></p>
<pre class="brush: php;">
1604716014
1478613278
6
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2010/01/25/mt_rand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>use Simple_html_dom php library with codeigniter</title>
		<link>http://itlivewire.com/devblog/2010/01/22/use-simple_html_dom-php-library-with-codeigniter/</link>
		<comments>http://itlivewire.com/devblog/2010/01/22/use-simple_html_dom-php-library-with-codeigniter/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:37:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=286</guid>
		<description><![CDATA[I was able to figure out how to run Simple_html_dom php library on codeigniter Download the simple html dom library here simple html dom I copied the file Simple_html_dom.php to /system/libraries Then in my controller I call it using require_once(&#8216;Simple_html_dom.php&#8217;); To use it, I initialized it using this line $html = new Simple_html_dom(); Load a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://t0.gstatic.com/images?q=tbn:yuqMAbcQ5fAVCM:http://www.allfacebook.com/images/codeigniter-lg.gif" alt="" /></p>
<p>I was able to figure out how to run Simple_html_dom php library on codeigniter</p>
<p>Download the simple html dom library here <a href="http://sourceforge.net/projects/simplehtmldom/files/">simple html dom</a></p>
<blockquote><p>I copied the file <strong>Simple_html_dom.php</strong> to</p>
<p><strong>/system/libraries</strong></p>
<p>Then in my controller I call it using</p>
<p><strong>require_once(&#8216;Simple_html_dom.php&#8217;); </strong></p>
<p>To use it, I initialized it using this line</p>
<p><strong>$html = new Simple_html_dom();</strong></p>
<p>Load a page or link using the line</p>
<p><strong>$html->load_file(&#8216;http://www.google.com&#8217;);</strong></p>
<p>and parse or find elements using this line</p>
<p><strong>$html->find(&#8216;table tr td&#8217;)->plaintext;</strong></p>
</blockquote>
<p>works fine and fits right to what I needed to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2010/01/22/use-simple_html_dom-php-library-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Excel time to Unix time</title>
		<link>http://itlivewire.com/devblog/2009/12/02/convert-excel-time-to-unix-time/</link>
		<comments>http://itlivewire.com/devblog/2009/12/02/convert-excel-time-to-unix-time/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 07:09:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[excel date]]></category>
		<category><![CDATA[excel time]]></category>
		<category><![CDATA[unix date]]></category>
		<category><![CDATA[unix time]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=196</guid>
		<description><![CDATA[When dealing in PHP with imported data from excel spreadsheets , you might encounter that excel dates looks very different. Excel time looks like this 40179 You cannot compare or compute dates in PHP if it looks like that, it should be on unixtime which looks like this 1104537600 Here is a quick function to [...]]]></description>
			<content:encoded><![CDATA[<p>When dealing in PHP with <strong>imported data from excel spreadsheets </strong>, you might encounter that excel dates looks very different. </p>
<p>Excel time looks like this <strong>40179</strong><br />
You cannot compare or compute dates in PHP if it looks like that, it should be on unixtime<br />
which looks like this<strong> 1104537600</strong></p>
<p>Here is a quick function to convert excel date to unixtime date</p>
<pre class="brush: php;">
&lt;?
$DayDifference = 25569; //Day difference between 1 January 1900 to 1 January 1970
$Day2Seconds = 86400;// no. of seconds in a day
$ExcelTime = 30128;//integer value stored in the Excel column
$ExcelTime = substr($ExcelTime,0,5);//trim excel time get only whole 5 digit
$UnixTime = ($ExcelTime - $DayDifference)*$Day2Seconds;
echo $UnixTime;
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2009/12/02/convert-excel-time-to-unix-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP ERROR Allowed memory size of 8388608 bytes exhausted</title>
		<link>http://itlivewire.com/devblog/2009/11/27/php-error-allowed-memory-size-of-8388608-bytes-exhausted/</link>
		<comments>http://itlivewire.com/devblog/2009/11/27/php-error-allowed-memory-size-of-8388608-bytes-exhausted/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 11:54:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=193</guid>
		<description><![CDATA[Error: PHP ERROR Allowed memory size of 8388608 bytes exhausted In php it means your memory use has exceeded the memory limit set by to execute a function. Solution: Type this above the function you are trying to excute ini_set(â€memory_limitâ€,â€16Mâ€); or any desired memory size you wish]]></description>
			<content:encoded><![CDATA[<p><strong>Error:</strong><br />
PHP ERROR Allowed memory size of 8388608 bytes exhausted<br />
In php it means your<strong> memory use has exceeded </strong>the memory limit set by to execute a function.</p>
<p><strong>Solution:</strong><br />
Type this above the function you are trying to excute<br />
<strong>ini_set(â€memory_limitâ€,â€16Mâ€);</strong><br />
or any desired memory size you wish</p>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2009/11/27/php-error-allowed-memory-size-of-8388608-bytes-exhausted/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 5.3 on Snow Leopard with mysqlnd</title>
		<link>http://itlivewire.com/devblog/2009/11/26/php-5-3-on-snow-leopard-with-mysqlnd/</link>
		<comments>http://itlivewire.com/devblog/2009/11/26/php-5-3-on-snow-leopard-with-mysqlnd/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 04:03:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysqlnd]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=189</guid>
		<description><![CDATA[On snow leopard the bundled version of PHP installed is 5.3 And it&#8217;s new PHP mysql driver is mysqlnd not the old one (ext/mysql) This might cause the following error: mysqlnd cannot connect to MySQL 4.1+ using old authentication Solution: type in mysql SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('newpwd'); Findings: Because mysqlnd has a bigger [...]]]></description>
			<content:encoded><![CDATA[<p>On snow leopard the bundled version of PHP installed is 5.3 And it&#8217;s new PHP mysql driver is mysqlnd not the old one (ext/mysql)</p>
<p>This might cause the following error:<br />
<strong>mysqlnd cannot connect to MySQL 4.1+ using old authentication</strong></p>
<p><strong>Solution:</strong><br />
type in mysql</p>
<pre class="brush: sql;">SET PASSWORD FOR 'some_user'@'some_host' = OLD_PASSWORD('newpwd');</pre>
<p><strong>Findings:</strong><br />
Because mysqlnd has a bigger password hash it will not be compatible anymore with the password written beforehand.</p>
<p>Ref:<br />
<a href="http://dev.mysql.com/doc/refman/5.1/en/old-client.html">http://dev.mysql.com/doc/refman/5.1/en/old-client.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2009/11/26/php-5-3-on-snow-leopard-with-mysqlnd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>codeigniter read or write a file</title>
		<link>http://itlivewire.com/devblog/2009/11/02/codeigniter-read-or-write-a-file/</link>
		<comments>http://itlivewire.com/devblog/2009/11/02/codeigniter-read-or-write-a-file/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 08:16:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://itlivewire.com/devblog/?p=163</guid>
		<description><![CDATA[In dealing with files on ci use the file helper http://codeigniter.com/user_guide/helpers/file_helper.html It is loaded using this line $this->load->helper(&#8216;file&#8217;); read a file with read_file() $data = read_file(&#8216;./path/to/file.php&#8217;); write a file with write_file(); write_file(&#8216;./path/to/file.php&#8217;, $data, &#8216;w+&#8217;); CI recommends &#8220;r+&#8221; but its better to use &#8220;w+&#8221;]]></description>
			<content:encoded><![CDATA[<p><img src="http://codeigniter.com/images/design/ci_logo2.gif" alt="" /></p>
<p>In dealing with files on ci use the <strong>file helper</strong><br />
<a href="http://codeigniter.com/user_guide/helpers/file_helper.html">http://codeigniter.com/user_guide/helpers/file_helper.html</a></p>
<p>It is loaded using this line<br />
$this->load->helper(&#8216;file&#8217;);<br />
<strong><br />
read a file with read_file()</strong><br />
$data = read_file(&#8216;./path/to/file.php&#8217;);</p>
<p><strong>write a file with write_file();</strong><br />
write_file(&#8216;./path/to/file.php&#8217;, $data, &#8216;w+&#8217;);</p>
<p>CI recommends &#8220;r+&#8221; but its better to use &#8220;w+&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://itlivewire.com/devblog/2009/11/02/codeigniter-read-or-write-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

