<?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>Fahdi&#039;s Personal Blog &#187; PHP</title>
	<atom:link href="http://www.fahdmurtaza.com/myblog/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fahdmurtaza.com/myblog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 30 Aug 2010 09:35:58 +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>PHP tip: Best way to get file extension</title>
		<link>http://www.fahdmurtaza.com/myblog/2010/07/25/best-way-to-get-file-extension.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2010/07/25/best-way-to-get-file-extension.html#comments</comments>
		<pubDate>Sun, 25 Jul 2010 09:21:14 +0000</pubDate>
		<dc:creator>Fahd</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tips]]></category>
		<category><![CDATA[code file extension php]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=714</guid>
		<description><![CDATA[I tried 100 ways to get the file extension from a complete file path including directories and file name with extension. This one works perfectly. This uses php function pathinfo to get the directory name, filename and its extension for you which is very handy. &#60;?php $fileinfo = pathinfo(“/path/to/your/file.php”); echo $fileinfo['dirname']; // Get directory echo $fileinfo['basename']; // Get file [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2010%2F07%2F25%2Fbest-way-to-get-file-extension.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2010%2F07%2F25%2Fbest-way-to-get-file-extension.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I tried 100 ways to get the file extension from a complete file path including directories and file name with extension. This one works perfectly. This uses php function <a title="PHP pathinfo " href="http://php.net/manual/en/function.pathinfo.php" target="_blank">pathinfo </a>to get the directory name, filename and its extension for you which is very handy.</p>
<div id="_mcePaste">&lt;?php</div>
<p><span id="more-714"></span></p>
<div></div>
<div id="_mcePaste">$fileinfo = pathinfo(“/path/to/your/file.php”);</div>
<div id="_mcePaste">echo $fileinfo['dirname']; // Get directory</div>
<div id="_mcePaste">echo $fileinfo['basename']; // Get file basename</div>
<div id="_mcePaste">echo $fileinfo['extension']; // Get file extension</div>
<div id="_mcePaste">echo $fileinfo['filename']; // Get file name</div>
<div id="_mcePaste">?&gt;</div>
<blockquote><p><code> </code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2010/07/25/best-way-to-get-file-extension.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Testing zend optimizer encoded PHP applications</title>
		<link>http://www.fahdmurtaza.com/myblog/2010/07/04/testing-zend-optimizer-encoded-php-applications.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2010/07/04/testing-zend-optimizer-encoded-php-applications.html#comments</comments>
		<pubDate>Sun, 04 Jul 2010 13:17:13 +0000</pubDate>
		<dc:creator>Fahd</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tips]]></category>
		<category><![CDATA[expressionengine testing php application 'zend optimizer' encoded]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=664</guid>
		<description><![CDATA[I am working on an expressionengine application these days. As I am using the beta version of expression engine until they release the final version, so the source files are encoded with the zend optimizer. Zend optimizer has a limitation that it can&#8217;t work with version 5.3 of PHP so far. I had the latest [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2010%2F07%2F04%2Ftesting-zend-optimizer-encoded-php-applications.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2010%2F07%2F04%2Ftesting-zend-optimizer-encoded-php-applications.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I am working on an expressionengine application these days. As I am using the beta version of expression engine until they release the final version, so the source files are encoded with the zend optimizer. Zend optimizer has a limitation that it can&#8217;t work with version 5.3 of PHP so far.<a href="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2010/07/expressionengine_logo.png"><img src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2010/07/expressionengine_logo-150x150.png" alt="" title="expressionengine_logo" width="150" height="150" class="alignright size-thumbnail wp-image-705" /></a></p>
<p>I had the latest XAMPP installed on my Windows VISTA machine for a year now but I found out that Zend optimiser isn&#8217;t compatible with version of PHP it provided i.e PHP 5.3, so I downloaded the version 1.6.8 of XAMPP from http://sourceforge.net/projects/xampp/files/ which has the older version of PHP i.e 5.2 which is compatible with Zend Optimizer.<span id="more-664"></span></p>
<p>Now here is the thing, I downloaded the Zend Optimizer from <a href="http://www.zend.com/en/products/guard/zend-optimizer" target="_blank">this link</a> and installed it.  In its installation steps it asks you for two locations which you have to tell it correctly or else it will not work properly.</p>
<ol>
<li>The path to php.ini</li>
<li>The path to Apache websrver&#8217;s root.</li>
</ol>
<p>Based on the installation directory of your XAMPP, you can select appropriate directories in these steps. I chose default <em><strong>C:\xampp </strong><span style="font-style: normal;">while installing XAMPP,  so I selected <strong><em>C:\xampp\apache\bin </em><span style="font-weight: normal;">and C:\xampp\apache for the Steps 1 and 2 respectively. </span></strong></span></em></p>
<p>And before that, using XAMPP control panel, I had stopped the Apache so when the configuration changes take place, the next time apache runs, it loads this new php.ini file which is changed by the zend optimizer installation.</p>
<p>Next thing you want to do is, check the php info using <strong><em>phpinfo.php</em></strong> file using the follwing url.</p>
<p><a href="http://localhost/xampp/phpinfo.php">http://localhost/xampp/phpinfo.php</a></p>
<p>It will open up a page with a bunch of information. Look for the text  <strong><em>Loaded Configuration File <span style="font-style: normal;"><span style="font-weight: normal;">and open the same php file using windows explorer.</span></span></em></strong></p>
<p><strong><em><span style="font-style: normal;"><span style="font-weight: normal;">For me it was</span></span></em></strong></p>
<table border="0" cellpadding="3" width="600">
<tbody>
<tr>
<td>Loaded Configuration File</td>
<td>C:\xampp\apache\bin\php.ini</td>
</tr>
</tbody>
</table>
<p>So I opened the php.ini folder and searched for the line where Zend Optimiser properties were mentioned and</p>
<p><code></p>
<div id="_mcePaste">[Zend]</div>
<div id="_mcePaste">zend_extension_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\ZendExtensionManager.dll"</div>
<div id="_mcePaste">zend_extension_manager.optimizer_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\Optimizer-3.3.0"</div>
<div id="_mcePaste"><strong>zend_optimizer.enable_loader = 0</strong></div>
<div id="_mcePaste">zend_optimizer.optimization_level=15</div>
<div id="_mcePaste">;zend_optimizer.license_path =</div>
<div id="_mcePaste">; Local Variables:</div>
<div id="_mcePaste">; tab-width: 4</div>
<div id="_mcePaste">; End:</div>
<p>[Zend]zend_extension_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\ZendExtensionManager.dll"zend_extension_manager.optimizer_ts="C:\Program Files\Zend\ZendOptimizer-3.3.0\lib\Optimizer-3.3.0"zend_optimizer.enable_loader = 1zend_optimizer.optimization_level=15;zend_optimizer.license_path =; Local Variables:; tab-width: 4; End:</p>
<p></code></p>
<p>In the above code I changed</p>
<p><code><br />
zend_optimizer.enable_loader = 0<br />
</code></p>
<p>to</p>
<p><code><br />
zend_optimizer.enable_loader = 1<br />
</code></p>
<p>So its loaded the next time I start the apache.<br />
<a href="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2010/07/php_doodle.png"><img src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2010/07/php_doodle-150x150.png" alt="" title="php_doodle" width="150" height="150" class="alignright size-thumbnail wp-image-710" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2010/07/04/testing-zend-optimizer-encoded-php-applications.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP: Text cropping with defining the number of characters, words or sentences</title>
		<link>http://www.fahdmurtaza.com/myblog/2009/03/18/585.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2009/03/18/585.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 09:53:50 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[characters]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[crop by number of]]></category>
		<category><![CDATA[crop text]]></category>
		<category><![CDATA[sentences]]></category>
		<category><![CDATA[string manipulation]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=585</guid>
		<description><![CDATA[I was asked to develop the functionality in a such a way that text can be cropped in these three ways.

   1. With defining the number of words.
   2. With defining the numbers of characters.
   3. With defining the number of sentences.

Here is a set of functions that helps you crop a text in three different ways. The usage of the function is also mentioned at the end f the script.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F18%2F585.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F18%2F585.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I have recently been working on PHP RSS reader script that was supposed to do three different things with RSS description text. To make a teaser RSS text, I was asked to develop the functionality in a such a way that text can be cropped in these three ways.</p>
<ul>
<li><strong>with defining the number of words.</strong></li>
<li><strong>with defining the numbers of characters.</strong></li>
<li><strong>with defining the number of sentences.</strong></li>
</ul>
<p>Here is a set of  functions that helps you crop a text in three different ways. The usage of the function is also mentioned at the end f the script.<span id="more-585"></span><br />
<code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php</span></span></code></p>
<p><span style="color: #ff8000;">/**<br />
* cropsentence()<br />
*<br />
* @param mixed $str<br />
* @param mixed $noof<br />
* @param integer $mode<br />
// 0 means crop by no of characters // 1 means crop by no of sentences // 2 means crop by number of words<br />
* @param string $appendwith<br />
* @return<br />
*/<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">cropsentence</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$noof</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$mode </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$appendwith </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;&#8230;&#8221;</span><span style="color: #007700;">)<br />
{<br />
if (</span><span style="color: #0000bb;">strlen</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">) &gt; </span><span style="color: #0000bb;">$chars</span><span style="color: #007700;">) {<br />
if (</span><span style="color: #0000bb;">$mode </span><span style="color: #007700;">== </span><span style="color: #0000bb;">0</span><span style="color: #007700;">) { </span><span style="color: #ff8000;">// 0 means crop by no of characters<br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">= </span><span style="color: #0000bb;">substr</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$noof</span><span style="color: #007700;">);<br />
} elseif (</span><span style="color: #0000bb;">$mode </span><span style="color: #007700;">== </span><span style="color: #0000bb;">1</span><span style="color: #007700;">) { </span><span style="color: #ff8000;">// 1 means crop by no of sentences<br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">= </span><span style="color: #0000bb;">getLeadingSentences</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$noof</span><span style="color: #007700;">);<br />
} elseif (</span><span style="color: #0000bb;">$mode </span><span style="color: #007700;">== </span><span style="color: #0000bb;">2</span><span style="color: #007700;">) { </span><span style="color: #ff8000;">// 2 means crop by number of words<br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">= </span><span style="color: #0000bb;">wordTrim</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$noof</span><span style="color: #007700;">);</span></p>
<p>} elseif (<span style="color: #0000bb;">$mode </span><span style="color: #007700;">&lt; </span><span style="color: #0000bb;">0 </span><span style="color: #007700;">|| </span><span style="color: #0000bb;">$mode </span><span style="color: #007700;">&gt; </span><span style="color: #0000bb;">2</span><span style="color: #007700;">) { </span><span style="color: #ff8000;">// others means do nothing<br />
</span><span style="color: #007700;">echo </span><span style="color: #dd0000;">&#8220;The current mode is not correct.&#8221;</span><span style="color: #007700;">;<br />
}<br />
</span><span style="color: #0000bb;">$str </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$str </span><span style="color: #007700;">. </span><span style="color: #0000bb;">$appendwith</span><span style="color: #007700;">;<br />
return </span><span style="color: #0000bb;">$str</span><span style="color: #007700;">;<br />
} else {<br />
return </span><span style="color: #0000bb;">$str</span><span style="color: #007700;">;<br />
}<br />
}</span></p>
<p><span style="color: #ff8000;">//getLeadingSentences<br />
//Copyright (c) 2000 Jason R. Pitoniak.  All rights reserved.<br />
//jason@interbrite.com http://www.interbrite.com</span></p>
<p>//If you find this code useful, find a bug, or have a suggestion,<br />
//please email me.  Feel free to use this code for any purpose.</p>
<p>/**<br />
* getLeadingSentences()<br />
*<br />
* @param mixed $data<br />
* @param mixed $max<br />
* @return<br />
*/<br />
<span style="color: #007700;">function </span><span style="color: #0000bb;">getLeadingSentences</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$data</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//given string $data, will return the first $max sentences in that string</span></p>
<p>//in: $data = the string to parse, $max = maximum # of sentences to return<br />
//returns: string containing the first $max sentences<br />
//(If the # of sentences in the string is less than $max,<br />
//then entire string will be returned.)</p>
<p>//a sentence is any charactors except ., !, and ?<br />
//any number of times,  plus one or more .s, ?s, or !s<br />
//and any leading or trailing whitespace:<br />
<span style="color: #0000bb;">$re </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;^s*[^.?!]+[.?!]+s*&#8221;</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$out </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;&#8221;</span><span style="color: #007700;">;<br />
for (</span><span style="color: #0000bb;">$i </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i </span><span style="color: #007700;">&lt; </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i</span><span style="color: #007700;">++) {<br />
if (</span><span style="color: #0000bb;">ereg</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$re</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$data</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$match</span><span style="color: #007700;">)) {<br />
</span><span style="color: #ff8000;">//if a sentence is found, take it out of $data and add it to $out<br />
</span><span style="color: #0000bb;">$out </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">$match</span><span style="color: #007700;">[</span><span style="color: #0000bb;">0</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$data </span><span style="color: #007700;">= </span><span style="color: #0000bb;">ereg_replace</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$re</span><span style="color: #007700;">, </span><span style="color: #dd0000;">&#8220;&#8221;</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$data</span><span style="color: #007700;">);<br />
} else {<br />
</span><span style="color: #0000bb;">$i </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">;<br />
}<br />
}<br />
return </span><span style="color: #0000bb;">$out</span><span style="color: #007700;">;<br />
}</span></p>
<p><span style="color: #ff8000;">/**<br />
* getLeadingWords()<br />
*<br />
* @param mixed $data<br />
* @param mixed $max<br />
* @return<br />
*/<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">getLeadingWords</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$data</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #ff8000;">//given string $data, will return the first $max sentences in that string</span></p>
<p>//in: $data = the string to parse, $max = maximum # of sentences to return<br />
//returns: string containing the first $max sentences<br />
//(If the # of sentences in the string is less than $max,<br />
//then entire string will be returned.)</p>
<p>//a sentence is any charactors except ., !, and ?<br />
//any number of times,  plus one or more .s, ?s, or !s<br />
//and any leading or trailing whitespace:<br />
<span style="color: #0000bb;">$re </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;^s*[^.?!]+[.?!]+s*&#8221;</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$out </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;&#8221;</span><span style="color: #007700;">;<br />
for (</span><span style="color: #0000bb;">$i </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i </span><span style="color: #007700;">&lt; </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i</span><span style="color: #007700;">++) {<br />
if (</span><span style="color: #0000bb;">ereg</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$re</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$data</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$match</span><span style="color: #007700;">)) {<br />
</span><span style="color: #ff8000;">//if a sentence is found, take it out of $data and add it to $out<br />
</span><span style="color: #0000bb;">$out </span><span style="color: #007700;">.= </span><span style="color: #0000bb;">$match</span><span style="color: #007700;">[</span><span style="color: #0000bb;">0</span><span style="color: #007700;">];<br />
</span><span style="color: #0000bb;">$data </span><span style="color: #007700;">= </span><span style="color: #0000bb;">ereg_replace</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$re</span><span style="color: #007700;">, </span><span style="color: #dd0000;">&#8220;&#8221;</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$data</span><span style="color: #007700;">);<br />
} else {<br />
</span><span style="color: #0000bb;">$i </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$max</span><span style="color: #007700;">;<br />
}<br />
}<br />
return </span><span style="color: #0000bb;">$out</span><span style="color: #007700;">;<br />
}</span></p>
<p><span style="color: #ff8000;">/**<br />
* wordTrim()<br />
*<br />
* @param mixed $str<br />
* @param mixed $len<br />
* @return<br />
*/<br />
</span><span style="color: #007700;">function </span><span style="color: #0000bb;">wordTrim</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$len</span><span style="color: #007700;">)<br />
{<br />
</span><span style="color: #0000bb;">$wordCount </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$charCount </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">;</span></p>
<p><span style="color: #0000bb;">$length </span><span style="color: #007700;">= </span><span style="color: #0000bb;">strlen</span><span style="color: #007700;">(</span><span style="color: #0000bb;">strip_tags</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">));<br />
for (</span><span style="color: #0000bb;">$i </span><span style="color: #007700;">= </span><span style="color: #0000bb;">0</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i </span><span style="color: #007700;">&lt; </span><span style="color: #0000bb;">$length</span><span style="color: #007700;">; </span><span style="color: #0000bb;">$i</span><span style="color: #007700;">++) {<br />
if (</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">[</span><span style="color: #0000bb;">$i</span><span style="color: #007700;">] == </span><span style="color: #dd0000;">&#8216; &#8217;</span><span style="color: #007700;">) {<br />
</span><span style="color: #0000bb;">$wordCount</span><span style="color: #007700;">++;<br />
</span><span style="color: #0000bb;">$charCount</span><span style="color: #007700;">++;<br />
if (</span><span style="color: #0000bb;">$wordCount </span><span style="color: #007700;">== </span><span style="color: #0000bb;">$len</span><span style="color: #007700;">)<br />
break;<br />
} else {<br />
</span><span style="color: #0000bb;">$charCount</span><span style="color: #007700;">++;<br />
} </span><span style="color: #ff8000;"># end if<br />
</span><span style="color: #007700;">} </span><span style="color: #ff8000;"># end for loop</span></p>
<p><span style="color: #0000bb;">$newstr </span><span style="color: #007700;">= </span><span style="color: #0000bb;">substr</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">0</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$charCount</span><span style="color: #007700;">);<br />
return </span><span style="color: #0000bb;">$newstr</span><span style="color: #007700;">;<br />
} </span><span style="color: #ff8000;"># end function</span></p>
<p># Example used for testing purpose</p>
<p><span style="color: #0000bb;">$str2 </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;Hello there I work for you. I have been working for other guys, but you are the coolest guy among them.<br />
Also I really like the way you guide me with new technologies and the latest trends. You always tell me to keep working hard!&#8221;</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">cropsentence</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str2</span><span style="color: #007700;">, </span><span style="color: #0000bb;">22</span><span style="color: #007700;">, </span><span style="color: #0000bb;">2</span><span style="color: #007700;">);</span></p>
<p><span style="color: #0000bb;">?&gt;</span></p>
<h3>Usage</h3>
<p><span style="color: #0000bb;">cropsentence</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$str</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$noof</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$mode</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$appendwith </span><span style="color: #007700;">);</span></p>
<p><strong>$str:</strong> This is the string / text to be cropped</p>
<p><strong>$noof: </strong>Number of characters/words/sentences based on the $mode parameter</p>
<p><strong>$mode: </strong>Three values of $mode can be defined</p>
<p>1. <strong>0</strong> means crop by no of characters.<br />
2. <strong>1 </strong>means crop by no of sentences .<br />
3.<strong> 2</strong> means crop by number of words.</p>
<p><strong>$appendwith: </strong>This can be any characters like &#8216;&#8230;&#8217; , &#8216;&#8230;more&#8217; etc which will be appended with the cropped text when its returned.</p>
<p><strong>Download:</strong></p>
<p>You can download the script here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2009/03/18/585.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to make sure your PHP RSS feed reader doesn&#8217;t mess up</title>
		<link>http://www.fahdmurtaza.com/myblog/2009/03/18/how-to-make-sure-your-php-rss-feed-reader-doesnt-mess-up.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2009/03/18/how-to-make-sure-your-php-rss-feed-reader-doesnt-mess-up.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 07:20:00 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[crop html]]></category>
		<category><![CDATA[crop text]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[reader]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[strip_tags]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=579</guid>
		<description><![CDATA[This post helps you with cropping long text into small with taking care of html tags that can get cropped in the mid due to unknown length of cropping.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F18%2Fhow-to-make-sure-your-php-rss-feed-reader-doesnt-mess-up.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F18%2Fhow-to-make-sure-your-php-rss-feed-reader-doesnt-mess-up.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I was recently working on a custom RSS feed reader where the prior most concern of the client was being able to crop the text with respect to the</p>
<ol>
<li>Number of words.</li>
<li>Numbers of characters.</li>
<li>Number of sentences.<span id="more-579"></span></li>
</ol>
<p>So a very important measure had to be taken. Since the cropping can end up giving us a broken link if its text  is cropped before the &lt;/a&gt; tag, our output can end up as a disaster.</p>
<p>So here is a little script that can help you strip off your html tags in such situations.<br />
<code><br />
&lt;?php</code></p>
<p><code>$text = "This is a link to &lt;a href='http://www.fahdmurtaza.com/myblog/'&gt;Fahd Murtaza's &lt;/a&gt; site!";<br />
echo strip_tags($text, "<a>");</a></code></p>
<p><code><a>?&gt;</a></code></p>
<p>So <strong>strip_tags</strong> would end up removing anything from the <strong>$text</strong>. The second parameter of the <strong>strip_tags</strong> will simply declare any html tags you want to neglect while stripping the text. Off course you will need to deal with them separately in text cropping situations like I had.</p>
<p>Here is one more example.</p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000;"> <span style="color: #0000bb;">&lt;?php<br />
$text </span><span style="color: #007700;">= </span><span style="color: #dd0000;">'&lt;p&gt;Test paragraph.&lt;/p&gt;&lt;!-- Comment --&gt; &lt;a href="#fragment"&gt;Other text&lt;/a&gt;'</span><span style="color: #007700;">;<br />
echo </span><span style="color: #0000bb;">strip_tags</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$text</span><span style="color: #007700;">);<br />
echo </span><span style="color: #dd0000;">"\n"</span><span style="color: #007700;">;</p>
<p></span><span style="color: #ff8000;">// Allow &lt;p&gt; and &lt;a&gt;<br />
</span><span style="color: #007700;">echo </span><span style="color: #0000bb;">strip_tags</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$text</span><span style="color: #007700;">, </span><span style="color: #dd0000;">'&lt;p&gt;&lt;a&gt;'</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?&gt;</span></span></code></div>
<div class="phpcode"></div>
<div class="phpcode">For more infomation, please check this function&#8217;s reference on <a title="strip_tags PHP Function" href="http://www.php.net/strip_tags" target="_blank">PHP&#8217;s official website</a>.</div>
<div class="phpcode"></div>
<div class="phpcode">Also if you are interested in getting the PHP RSS reader script I did, I would encourage you to visit this link  of my next post. Also, if you are intersted in having the script that does the cropping by</div>
<div class="phpcode">
<ol>
<li>Number of words.</li>
<li>Numbers of characters.</li>
<li>Number of sentences.</li>
</ol>
<p>you can get it here.</p></div>
<div class="phpcode"></div>
<div class="phpcode"></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2009/03/18/how-to-make-sure-your-php-rss-feed-reader-doesnt-mess-up.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I am on home page of oDesk, feels great</title>
		<link>http://www.fahdmurtaza.com/myblog/2009/03/17/i-am-on-home-page-of-odesk-feels-great.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2009/03/17/i-am-on-home-page-of-odesk-feels-great.html#comments</comments>
		<pubDate>Tue, 17 Mar 2009 04:33:55 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[expert]]></category>
		<category><![CDATA[fahd]]></category>
		<category><![CDATA[Fahd Murtaza]]></category>
		<category><![CDATA[murtaza]]></category>
		<category><![CDATA[oDesk]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=571</guid>
		<description><![CDATA[Hi guys I am feeling good right now. Have been working on oDesk from Feb 17, 2009. And its good you get paid on hourly basis. I like oDesk the most among freelancing sites I have worked on. Anyhow, I took a few screen shots to show you that I was once featured on home [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F17%2Fi-am-on-home-page-of-odesk-feels-great.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2009%2F03%2F17%2Fi-am-on-home-page-of-odesk-feels-great.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Hi guys</p>
<p>I am feeling good right now. Have been working on oDesk from Feb 17, 2009. And its good you get paid on hourly basis. I like oDesk the most among freelancing sites I have worked on. Anyhow, I took a few screen shots to show you that I was once featured on home page on oDesk.</p>
<p><a href="http://www.odesk.com/users/~~869cd6b2b81d3b45"><img class="alignnone size-medium wp-image-575" title="Fahd Murtaza featured on home page of odesk" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2009/03/fahd-murtaza-featured-on-home-page-of-odesk-292x300.png" alt="" width="292" height="300" /></a></p>
<p><span id="more-571"></span></p>
<div id="attachment_574" class="wp-caption alignnone" style="width: 310px"><a href="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2009/03/tests.png"><img class="size-medium wp-image-574" title="oDesk Tests passed by Fahd Murtaza" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2009/03/tests-300x131.png" alt="Fahd Murtaza's Passed Expert Rating Tests" width="300" height="131" /></a><p class="wp-caption-text">Fahd Murtaza</p></div>
<div id="attachment_572" class="wp-caption alignnone" style="width: 310px"><a href="http://www.odesk.com/users/~~869cd6b2b81d3b45"><img class="size-medium wp-image-572" title="Profile Overview" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2009/03/profile-overview-300x131.png" alt="My profile overview on oDesk" width="300" height="131" /></a><p class="wp-caption-text">My profile overview on oDesk</p></div>
<div id="attachment_573" class="wp-caption alignnone" style="width: 310px"><a href="http://www.odesk.com/users/~~869cd6b2b81d3b45"><img class="size-medium wp-image-573" title="Resume Profile on oDesk" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2009/03/profile-resume-300x131.png" alt="My Resume Profile on oDesk" width="300" height="131" /></a><p class="wp-caption-text">My Resume Profile on oDesk</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2009/03/17/i-am-on-home-page-of-odesk-feels-great.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yahoo Shortcuts</title>
		<link>http://www.fahdmurtaza.com/myblog/2008/09/09/yahoo-shortcuts.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2008/09/09/yahoo-shortcuts.html#comments</comments>
		<pubDate>Tue, 09 Sep 2008 07:31:55 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[Blogging Engines]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=452</guid>
		<description><![CDATA[As you type the content for your blog post, this plugin looks for Flickr Photos, Maps to any locations that you might mention in the post, any products that are listed or even related news to your blogs post. If your content regularly mentions some companies regularly, Yahoo shortcuts can bring up latest financial information [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F09%2Fyahoo-shortcuts.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F09%2Fyahoo-shortcuts.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><div id="attachment_453" class="wp-caption alignleft" style="width: 310px"><a href="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/09/yahoo-shortcuts.jpg"><img class="size-medium wp-image-453" title="Yahoo Shortcuts" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/09/yahoo-shortcuts-300x182.jpg" alt=" Enhance your blog posts with Yahoo! Shortcuts." width="300" height="182" /></a><p class="wp-caption-text"> Enhance your blog posts with Yahoo! Shortcuts.</p></div>As you type the content for your blog post, this plugin looks for Flickr Photos, Maps to any locations that you might mention in the post, any products that are listed or even related news to your blogs post.</p>
<p>If your content regularly mentions some companies regularly, Yahoo shortcuts can bring up latest financial information related to that company.</p>
<p>Relevant search results would also come up for certain terms like in the image shown UNIX Pipes would pop up a Yahoo shortcut with relevant contextual search results. Some bloggers may find some shortcuts annoying and irrelevant to their blogs content, but some might really find it useful. It all depends on what you blog about.<span id="more-452"></span></p>
<p>However the best feature I think is the auto detection of relevant images to your blog post. Images can really enlighten the posts and make them more interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2008/09/09/yahoo-shortcuts.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting comma separated integer/ digit  values to an array of integers</title>
		<link>http://www.fahdmurtaza.com/myblog/2008/09/09/converting-comma-separated-integer-digit-values-to-an-array-of-integers.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2008/09/09/converting-comma-separated-integer-digit-values-to-an-array-of-integers.html#comments</comments>
		<pubDate>Tue, 09 Sep 2008 00:00:00 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code segment]]></category>
		<category><![CDATA[comma separated]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[digits]]></category>
		<category><![CDATA[integers]]></category>
		<category><![CDATA[In_array()]]></category>
		<category><![CDATA[php split()]]></category>
		<category><![CDATA[string conversion]]></category>
		<category><![CDATA[string to array]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=450</guid>
		<description><![CDATA[OK here is the code to convert a comma separated string of integer/ digit value to an array $csvintegers='1,2,3,4,7'; $listvals=split(",",$csvintegers); ?&#62; You can always compare whether if an integer is present in a string or not. The code to do so is &#60;? if (in_array(1,$listvals)) { ?&#62; 1 exists&#60;br/&#62; &#60;? }?&#62; &#60;? if (in_array(9,$listvals)) { [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F09%2Fconverting-comma-separated-integer-digit-values-to-an-array-of-integers.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F09%2Fconverting-comma-separated-integer-digit-values-to-an-array-of-integers.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>OK here is the code to convert a comma separated string of integer/ digit value to an array<br />
<code><br />
$csvintegers='1,2,3,4,7';<br />
$listvals=split(",",$csvintegers);<br />
?&gt;</code></p>
<p>You can always compare whether if an integer is present in a string or not. The code to do so is<span id="more-450"></span><br />
<code>&lt;? if (in_array(1,$listvals)) { ?&gt;<br />
1 exists&lt;br/&gt;<br />
&lt;? }?&gt;<br />
&lt;? if (in_array(9,$listvals)) { ?&gt;<br />
9 exists&lt;br/&gt;<br />
&lt;? }?&gt;</code></p>
<p>So the above code after running one after another, will output<br />
<strong><code>1 exists</code></strong></p>
<p>So basically this code</p>
<p><strong><code>&lt;? if (in_array(1,$listvals)) { ?&gt; </code></strong></p>
<p>checks whether 1 is in the array <strong>$listvals. </strong><strong>$listvals</strong> was created by splitting (using PHP <strong>split() </strong>function ) the comma separated string of integers (<strong><code>$csvintegers</code></strong>) with respect to commas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2008/09/09/converting-comma-separated-integer-digit-values-to-an-array-of-integers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert date formats between PHP and MySQL (mm/dd/yyyy to yyyy-mm-dd)</title>
		<link>http://www.fahdmurtaza.com/myblog/2008/09/08/convert-date-formats-between-php-and-mysql-mm-dd-yyyy-to-yyyy-mm-dd.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2008/09/08/convert-date-formats-between-php-and-mysql-mm-dd-yyyy-to-yyyy-mm-dd.html#comments</comments>
		<pubDate>Mon, 08 Sep 2008 05:26:16 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[date conversion]]></category>
		<category><![CDATA[date picker]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mm/dd/yyyy]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[yyyy-mm-dd]]></category>
		<category><![CDATA[yyyy-mm-dd hh:mm:ss]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=412</guid>
		<description><![CDATA[I have a view in HWC where I am using Javascript DHTML date picker script to pick the date and insert into test field. By the way HWC is the PHP-MVC (using codeigniter) application I am working on. So as you see, the date pickers default format is mm/dd/yyyy,  which is not acceptable by MySQL [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F08%2Fconvert-date-formats-between-php-and-mysql-mm-dd-yyyy-to-yyyy-mm-dd.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F09%2F08%2Fconvert-date-formats-between-php-and-mysql-mm-dd-yyyy-to-yyyy-mm-dd.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I have a view in HWC where I am using Javascript DHTML date picker script to pick the date and insert into test field.  By the way HWC is the PHP-MVC (using codeigniter) application I am working on.</p>
<div id="attachment_446" class="wp-caption alignright" style="width: 310px"><a href="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/09/date_picker_view.jpg"><img class="size-medium wp-image-446" title="DHTML Date Picker View" src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/09/date_picker_view-300x164.jpg" alt="Date Picker in dhtml/Javascript " width="300" height="164" /></a><p class="wp-caption-text">Date Picker in dhtml/Javascript </p></div>
<p><span id="more-412"></span>So as you see, the date pickers default format is <strong>mm/dd/yyyy</strong>,  which is not acceptable by MySQL date/time field as it is, so we need a little processing to make MySQL happy enough to store it <img src='http://www.fahdmurtaza.com/myblog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Converting  mm/dd/yyyy to yyyy-mm-dd</strong></p>
<p><code>$date=split("/",$_POST['date']);<br />
// where the $_POST['date'] is a value posted by form in mm/dd/yy format<br />
$dated=$date[2]."-".$date[0]."-".$date[1];<br />
// The string dated is now in yyyy-mm-dd format<br />
echo $dated;</code></p>
<p>For example, the date entered through form was 09/02/2009, after processing it will be stored in $dated as 2009-02-09. Pretty kool yeah? Just notice if you have / as  I am happy if helps you. You need help with more similar stuff, post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2008/09/08/convert-date-formats-between-php-and-mysql-mm-dd-yyyy-to-yyyy-mm-dd.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Codeigniter &#8211; Clean URLs &#8211; Apache mod rewrite : Removing /index.php/ from URL in CodeIgniter Application</title>
		<link>http://www.fahdmurtaza.com/myblog/2008/08/22/codeigniter-clean-urls-apache-mod-rewrite-removing-indexphp-from-url-in-codeigniter-application.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2008/08/22/codeigniter-clean-urls-apache-mod-rewrite-removing-indexphp-from-url-in-codeigniter-application.html#comments</comments>
		<pubDate>Fri, 22 Aug 2008 07:09:18 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[igniter]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[mod rewrite]]></category>
		<category><![CDATA[permalinks]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[urls]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/?p=417</guid>
		<description><![CDATA[This article discusses how you can enable mod rewrite to work with apache server so you can get those clean urls. CodeIgniter has built in support for clean urls so all you have to do is to activate this using the method described in this article.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F08%2F22%2Fcodeigniter-clean-urls-apache-mod-rewrite-removing-indexphp-from-url-in-codeigniter-application.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F08%2F22%2Fcodeigniter-clean-urls-apache-mod-rewrite-removing-indexphp-from-url-in-codeigniter-application.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>OK readers, here is a simple method to achieve clean urls with your PHP application developed in CodeIgniter.</p>
<p>Please note that this method is applicable only to applications developed in CodeIgniter. Much of the content has been taken from CodeIgniter wiki but rewritten in my own way.<span id="more-417"></span></p>
<p>This article explains how to take away “index.php” from your CI application URLs. However, it does NOT remove the need for Index.php, which is the CI front controller i.e. even though Index.php will not appear in the URL, it still needs to be present at the top level of your site (above the /system/ directory).  To quote the User Guide,</p>
<blockquote><p>You can easily remove this file by using a .htaccess file with some simple rules.</p></blockquote>
<p>You need to perform the following steps to get this working:</p>
<p><strong>1. Create a .htaccess file to configure the rewrite engine</strong></p>
<p><strong>2. Set $config[’index_page’] to an empty string</strong></p>
<p><strong>3. Make sure your apache uses the mod_rewrite module</strong></p>
<p><strong>4. Make sure apache is configured to accept needed .htaccess directives</strong></p>
<p><strong>5. Restart apache and test</strong></p>
<h3>1. Create your .htaccess file</h3>
<p>Create a new file named .htaccess and put it in your web directory</p>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">IfModule mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">c</span><span style="color: #007700;">&gt;<br />
</span><span style="color: #ffffff;">RewriteEngine On<br />
RewriteBase </span><span style="color: #007700;">/</p>
<p><span style="color: #ff8000;">#Removes access to the system folder by users.<br />
#Additionally this will allow you to create a System.php controller,<br />
#previously this would not have been possible.<br />
#'system' can be replaced if you have renamed your system folder.<br />
</span><span style="color: #ffffff;">RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_URI} </span><span style="color: #007700;">^</span><span style="color: #ffffff;">system</span><span style="color: #007700;">.*<br />
</span><span style="color: #ffffff;">RewriteRule </span><span style="color: #007700;">^(.*)$ /</span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">/$</span><span style="color: #ffffff;">1 [L]</span></p>
<p><span style="color: #ff8000;">#Checks to see if the user is attempting to access a valid file,<br />
#such as an image or css document, if this isn't true it sends the<br />
#request to index.php<br />
</span><span style="color: #ffffff;">RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">f<br />
RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">d<br />
RewriteRule </span><span style="color: #007700;">^(.*)$ </span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">/$</span><span style="color: #ffffff;">1 [L]<br />
</span><span style="color: #007700;">&lt;/</span><span style="color: #ffffff;">IfModule</span><span style="color: #007700;">&gt;</span></p>
<p>&lt;</p>
<p><span style="color: #ffffff;">IfModule </span><span style="color: #007700;">!</span><span style="color: #ffffff;">mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">c</span><span style="color: #007700;">&gt;<br />
</span><span style="color: #ff8000;"># If we don't have mod_rewrite installed, all 404's<br />
# can be sent to index.php, and everything works as normal.<br />
# Submitted by: ElliotHaughin</span></p>
<p></span></code><code><span style="color: #ffffff;">ErrorDocument 404 </span><span style="color: #007700;">/</span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php<br />
</span><span style="color: #007700;">&lt;/</span><span style="color: #ffffff;">IfModule</span><span style="color: #007700;">&gt;</span> </code></p>
</div>
<p>Notes for Windows users:<br />
To create this file you must open Command Prompt and type:<br />
copy con .htaccess [Enter]<br />
[Press CTRL + Z]<br />
A blank .htaccess file will be created. Now you can edit it using Notepad or your favorite text editor and copy the script above.</p>
<p>Note: Most Windows editors will assume that you are attempting to save an .htaccess file as a file with an extension and no filename. The Crimson Editor can be used to create and save .htaccess files and other files that have no filename.</p>
<p>Note: If your site is placed in subfolder specify the path in the “RewriteBase /subfolder/” line.</p>
<h3>2. Set $config[’index_page’]  to an empty string</h3>
<p>Open your</p>
<div class="codeblock"><code> <span style="color: #ffffff;">system</span><span style="color: #007700;">/</span><span style="color: #ffffff;">application</span><span style="color: #007700;">/</span><span style="color: #ffffff;">config</span><span style="color: #007700;">/</span><span style="color: #ffffff;">config</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span> </code></div>
<p>and find the line that assigns $config[’index_page’] a value, usually:</p>
<div class="codeblock"><code> <span style="color: #ffffff;">$config[</span><span style="color: #dd0000;">'index_page'</span><span style="color: #ffffff;">] </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"index.php"</span><span style="color: #007700;">;</span> </code></div>
<p>and change it to:</p>
<div class="codeblock"><code> <span style="color: #ffffff;">$config[</span><span style="color: #dd0000;">'index_page'</span><span style="color: #ffffff;">] </span><span style="color: #007700;">= </span><span style="color: #dd0000;">''</span><span style="color: #007700;">;</span> </code></div>
<p>Save the file.</p>
<h3>3. Make sure your apache has mod_rewrite activated</h3>
<p>This means that the apache must be configured to load the mod_rewrite module (or it might have it compiled-in). For module inclusion, usually you have to look for a line like this in httpd.conf or a file loaded by it (hint: use some quick file search utility to grep files with lines containing ‘rewrite’ string):</p>
<div class="codeblock"><code> <span style="color: #ffffff;">LoadModule rewrite_module </span><span style="color: #007700;">/</span><span style="color: #ffffff;">usr</span><span style="color: #007700;">/</span><span style="color: #ffffff;">lib</span><span style="color: #007700;">/</span><span style="color: #ffffff;">apache2</span><span style="color: #007700;">/</span><span style="color: #ffffff;">modules</span><span style="color: #007700;">/</span><span style="color: #ffffff;">mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">so</span> </code></div>
<p>If you’re running Apache2 type</p>
<div class="codeblock"><code> <span style="color: #ffffff;">a2enmod</span> </code></div>
<p>in the console and when prompted</p>
<div class="codeblock"><code> <span style="color: #ffffff;">rewrite</span> </code></div>
<p>to enable mod_rewrite.</p>
<p>On a Windows machine this line might look this way:</p>
<div class="codeblock"><code> <span style="color: #ffffff;">LoadModule rewrite_module modules</span><span style="color: #007700;">/</span><span style="color: #ffffff;">mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">so</span> </code></div>
<p>If it is commented out (# in front), make sure to uncomment it and save the file. Checking if the corresponding module exists may be a good idea as well (but it usually does).</p>
<h3>4. Make sure apache accepts needed .htaccess directives</h3>
<p>This means that apache is explicitly configured to allow .htaccess files to override those directives that you use in your .htaccess file from step 1. above.</p>
<p>It seems to be sufficient if you add these two lines to your &lt;Directory&gt; section where you configure the document root for your CI application:</p>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">Directory </span><span style="color: #dd0000;">"/some/absolute/path/htdocs"</span><span style="color: #007700;">&gt;<br />
...<br />
</span><span style="color: #ffffff;">Options FollowSymLinks<br />
AllowOverride FileInfo<br />
</span><span style="color: #007700;">...<br />
&lt;/</span><span style="color: #ffffff;">Directory</span><span style="color: #007700;">&gt;</span> </code></div>
<p>There might be other Options listed, just make sure you have <strong>FollowSymLinks</strong> as well.</p>
<p>Should you get a 500 Internal Server Error, try the following syntax:</p>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">Directory </span><span style="color: #dd0000;">"/some/absolute/path/htdocs"</span><span style="color: #007700;">&gt;<br />
</span><span style="color: #ffffff;">Options Indexes Includes FollowSymLinks MultiViews<br />
AllowOverride AuthConfig FileInfo<br />
Order allow</span><span style="color: #007700;">,</span><span style="color: #ffffff;">deny<br />
Allow from all<br />
</span><span style="color: #007700;">&lt;/</span><span style="color: #ffffff;">Directory</span><span style="color: #007700;">&gt;</span> </code></div>
<h3>5. Restart apache and test your application</h3>
<p><strong>Works? Congratulations!</strong></p>
<p>Doesn’t work? Ehrrr… well, do not give up; equip yourself with patience, double check all steps above and if it still does not work, post on the forum giving all details of your setup.</p>
<h3>How does URL rewriting work?</h3>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">IfModule mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">c</span><span style="color: #007700;">&gt;<br />
...<br />
&lt;/</span><span style="color: #ffffff;">IfModule</span><span style="color: #007700;">&gt;</span> </code></div>
<p>Do what is inside only if Apache has the mod_rewrite feature (by in place compilation, or loaded module).</p>
<div class="codeblock"><code> <span style="color: #ffffff;">RewriteEngine On</span> </code></div>
<p>Activate the URL rewriting engine, if not already done (in main Apache configuration file.</p>
<div class="codeblock"><code> <span style="color: #ffffff;">RewriteBase </span><span style="color: #ff8000;">/</span> </code></div>
<p>Define the part of the URL that won’t change nor be used for rewriting. In fact, this part will be removed before processing, and prepended after processing. This’s a good way to use subfolder-independent rewrite rules. For example, if your CodeIgniter index.php is placed in a virtual host directory, like /tests/, set RewriteBase to /tests/.</p>
<div class="codeblock"><code> <span style="color: #ffffff;">RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">f</span> </code></div>
<p>Condition to meet for RewriteRule activation. Here, we test if the requested filename does not exist.</p>
<div class="codeblock"><code> <span style="color: #ffffff;">RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">d</span> </code></div>
<p>Same as above, but we test for directory existence.</p>
<div class="codeblock"><code> <span style="color: #ffffff;">RewriteRule </span><span style="color: #007700;">^(.*)$ </span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">/$</span><span style="color: #ffffff;">1 [L]</span> </code></div>
<p>If RewriteCond conditions are met, this rule will be applied. It inserts index.php before the requested URI. The $1 represents the part of string enclosed by parentheses in left expression. The [L] means that this rule is the last one if rule is applied (thus stopping rewriting).</p>
<h2>Configuring mod_rewrite in the httpd.conf file</h2>
<p>The Apache mod_rewrite docs say</p>
<blockquote><p>While URL manipulations in per-server context are really fast and efficient, per-directory rewrites are slow and inefficient…</p></blockquote>
<p>. If you have access to your httpd.conf file, you’ll have better performance if you configure the rewrite rules in there.</p>
<p>You can add something like this to your httpd.conf:</p>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">IfModule mod_rewrite</span><span style="color: #007700;">.</span><span style="color: #ffffff;">c</span><span style="color: #007700;">&gt;<br />
</span><span style="color: #ffffff;">RewriteEngine On<br />
RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_URI} </span><span style="color: #007700;">!^(/</span><span style="color: #ffffff;">index\</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">|/</span><span style="color: #ffffff;">img</span><span style="color: #007700;">|/</span><span style="color: #ffffff;">js</span><span style="color: #007700;">|/</span><span style="color: #ffffff;">css</span><span style="color: #007700;">|/</span><span style="color: #ffffff;">robots\</span><span style="color: #007700;">.</span><span style="color: #ffffff;">txt</span><span style="color: #007700;">|/</span><span style="color: #ffffff;">favicon\</span><span style="color: #007700;">.</span><span style="color: #ffffff;">ico</span><span style="color: #007700;">)<br />
</span><span style="color: #ffffff;">RewriteRule </span><span style="color: #007700;">^(.*)$ /</span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">/$</span><span style="color: #ffffff;">1 [L]<br />
</span><span style="color: #007700;">&lt;/</span><span style="color: #ffffff;">IfModule</span><span style="color: #007700;">&gt;</span> </code></div>
<h2>Configuring mod_rewrite and virtual hosting with Apache 2.2</h2>
<div class="codeblock"><code> <span style="color: #007700;">&lt;</span><span style="color: #ffffff;">VirtualHost </span><span style="color: #007700;">*&gt;<br />
</span><span style="color: #ffffff;">ServerName www</span><span style="color: #007700;">.</span><span style="color: #ffffff;">mydomain</span><span style="color: #007700;">.</span><span style="color: #ffffff;">com<br />
DocumentRoot </span><span style="color: #007700;">/</span><span style="color: #ffffff;">path</span><span style="color: #007700;">/</span><span style="color: #ffffff;">to</span><span style="color: #007700;">/</span><span style="color: #ffffff;">ci</span><span style="color: #007700;">/</span><span style="color: #ffffff;">directory<br />
</span><span style="color: #007700;">&lt;</span><span style="color: #ffffff;">Directory </span><span style="color: #007700;">/</span><span style="color: #ffffff;">path</span><span style="color: #007700;">/</span><span style="color: #ffffff;">to</span><span style="color: #007700;">/</span><span style="color: #ffffff;">ci</span><span style="color: #007700;">/</span><span style="color: #ffffff;">directory</span><span style="color: #007700;">&gt;<br />
</span><span style="color: #ffffff;">RewriteEngine On<br />
RewriteBase </span><span style="color: #007700;">/<br />
</span><span style="color: #ffffff;">RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">f<br />
RewriteCond </span><span style="color: #007700;">%</span><span style="color: #ffffff;">{REQUEST_FILENAME} </span><span style="color: #007700;">!-</span><span style="color: #ffffff;">d<br />
RewriteRule </span><span style="color: #007700;">^(.*)$ </span><span style="color: #ffffff;">index</span><span style="color: #007700;">.</span><span style="color: #ffffff;">php</span><span style="color: #007700;">/$</span><span style="color: #ffffff;">1 [L]<br />
</span><span style="color: #007700;">&lt;/</span><span style="color: #ffffff;">Directory</span><span style="color: #007700;">&gt;<br />
&lt;/</span><span style="color: #ffffff;">VirtualHost</span><span style="color: #007700;">&gt;</span></code></div>
<div class="codeblock">Credits: <a href="http://codeigniter.com/wiki/mod_rewrite/" target="_blank">http://codeigniter.com/wiki/mod_rewrite/</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2008/08/22/codeigniter-clean-urls-apache-mod-rewrite-removing-indexphp-from-url-in-codeigniter-application.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>WordPress; the new cool version 2.5 enjoyyy</title>
		<link>http://www.fahdmurtaza.com/myblog/2008/03/30/wordpress-the-new-cool-version-25-enjoyyy.html</link>
		<comments>http://www.fahdmurtaza.com/myblog/2008/03/30/wordpress-the-new-cool-version-25-enjoyyy.html#comments</comments>
		<pubDate>Sun, 30 Mar 2008 21:54:23 +0000</pubDate>
		<dc:creator>ahmed</dc:creator>
				<category><![CDATA[Blogging Engines]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[blogging engine]]></category>
		<category><![CDATA[clean look]]></category>
		<category><![CDATA[cool features]]></category>
		<category><![CDATA[Cpanel]]></category>
		<category><![CDATA[fantastico]]></category>
		<category><![CDATA[latest]]></category>
		<category><![CDATA[latest release]]></category>
		<category><![CDATA[neat look]]></category>
		<category><![CDATA[publishing platform]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://www.fahdmurtaza.com/myblog/2008/03/30/wordpress-the-new-cool-version-25-enjoyyy.html</guid>
		<description><![CDATA[Yeah as always I am one complete day late to know about the new release of wordpress. Its really cool. I just downloaded and installed it. As its famous for its 5 minutes install; it has great new features and a neat and clean interface, I think a hundred times better than the previous version [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F03%2F30%2Fwordpress-the-new-cool-version-25-enjoyyy.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.fahdmurtaza.com%2Fmyblog%2F2008%2F03%2F30%2Fwordpress-the-new-cool-version-25-enjoyyy.html&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Yeah as always I am one complete day late to know about the new release of wordpress. Its really cool. I just downloaded and installed it. As its famous for its 5 minutes install; it has great new features and a neat and clean interface, I think a hundred times better than the previous version thats 2.3 if I am not wrong (2.3.3), yeah I just checked as I am writing this post on the old platform and I just needed to scroll down this post window (my wordpress blog is an auto install by Fantastico provided by my host in Cpanel)</p>
<p>Anyhow right now I am playing with the latest version (2.5)  and its simply awesome.</p>
<p>See the difference. Its just obvious. Its on full page for this blog post.<span id="more-294"></span></p>
<p><img src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/03/image002.jpg" alt="Old version wordpress 2.3.3" /></p>
<p>The Old version of wordpress i.e. 2.3.3</p>
<p><img src="http://www.fahdmurtaza.com/myblog/wp-content/uploads/2008/03/image004.jpg" alt="New wordpress 2.5 posting a new blog post" /></p>
<p>The new cool thing  wordpress i.e. 2.5</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fahdmurtaza.com/myblog/2008/03/30/wordpress-the-new-cool-version-25-enjoyyy.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
