<?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>dr_drsh Place &#187; PHP</title>
	<atom:link href="http://mostafa.mosmar.com/blog/category/technical/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://mostafa.mosmar.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 06 Nov 2009 00:42:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Use is_null rather than == null</title>
		<link>http://mostafa.mosmar.com/blog/2009/09/21/use-is_null-rather-than-null/</link>
		<comments>http://mostafa.mosmar.com/blog/2009/09/21/use-is_null-rather-than-null/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 09:10:47 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/?p=126</guid>
		<description><![CDATA[While playing with strings one should be VERY VERY VERY cautious when trying to check for a &#8220;null&#8221; value PHP has the bad habit of considering empty strings to be &#8220;null&#8221; and &#8220;false&#8221; , for instance 1 2 3 4 $foo = ''; if&#40; $foo == null &#38;&#38; $foo == false &#41;&#123; echo &#34;So PHP [...]]]></description>
			<content:encoded><![CDATA[<p class="english-text" >While playing with strings one should be VERY VERY VERY cautious when trying to check for a &#8220;null&#8221; value</p>
<p class="english-text" >PHP has the bad habit of considering empty strings to be &#8220;null&#8221; and &#8220;false&#8221; , for instance</p>

<div class="english-text"  class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;So PHP actually considers empty strings to be null and false&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p class="english-text" ><span id="more-126"></span><br />
To avoid this either use</p>

<div class="english-text"  class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #009900;">&#41;</span>
<span style="color: #666666; font-style: italic;">//or</span>
<span style="color: #000088;">$foo</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">null</span></pre></td></tr></table></div>

<p class="english-text" >Try this code</p>

<div class="english-text"  class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'So PHP actually considers empty strings to be null AND false!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Using is_null() will return true only if $foo is null'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$foo</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Using === and !== also works well'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2009/09/21/use-is_null-rather-than-null/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Accessing the first element in associative PHP array</title>
		<link>http://mostafa.mosmar.com/blog/2009/08/05/accessing-the-first-element-in-associative-php-array/</link>
		<comments>http://mostafa.mosmar.com/blog/2009/08/05/accessing-the-first-element-in-associative-php-array/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 18:37:22 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Arrays]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/?p=109</guid>
		<description><![CDATA[Accessing the first element in a php array can be done as easy as this $myArray&#91;0&#93; = 'foo'; and you can also use &#8220;list&#8221; to access more than one index in one call list&#40; $first, $second, $third &#41; = $myArray; This approach , however, doesn&#8217;t work with associative arrays or arrays that have non-standard integer [...]]]></description>
			<content:encoded><![CDATA[<p class="english-text" >Accessing the first element in a php array can be done as easy as this</p>

<div class="english-text"  class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myArray</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: #0000ff;">'foo'</span><span style="color: #339933;">;</span></pre></div></div>

<p class="english-text" >and you can also use &#8220;<a href="http://www.php.net/manual/en/function.list.php">list</a>&#8221; to access more than one index in one call</p>

<div class="english-text"  class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$first</span><span style="color: #339933;">,</span> <span style="color: #000088;">$second</span><span style="color: #339933;">,</span> <span style="color: #000088;">$third</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$myArray</span><span style="color: #339933;">;</span></pre></div></div>

<p class="english-text" >This approach , however, doesn&#8217;t work with associative arrays or arrays that have non-standard integer index like</p>

<div class="english-text"  class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$stringIndexedArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'data'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'second'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nonStandardIntegerIndexedArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p class="english-text" >I have found two methods to access the first element in such arrays, one using &#8220;<a href="http://www.php.net/manual/en/function.reset.php">reset</a>&#8221; and the other using &#8220;<a href="http://www.php.net/manual/en/function.array-values.php">array_values</a>&#8221;</p>

<div class="english-text"  class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$stringIndexedArray</span><span style="color: #339933;">=</span> 
<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'first'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Data 1'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'second'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Data 2'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'third'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Data 3'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'forth'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Data 4'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'fifth'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Data 5'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//reset method</span>
<span style="color: #666666; font-style: italic;">//Average execution time : 2.8123000000003E-6</span>
<span style="color: #000088;">$firstElement</span> <span style="color: #339933;">=</span> <span style="color: #990000;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$stringIndexedArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//array_values method</span>
<span style="color: #666666; font-style: italic;">//Average execution time : 3.8123000000001E-6</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$firstElement</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$stringIndexedArray</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p class="english-text" >I&#8217;ve done some profiling and turns out that &#8220;<a href="http://www.php.net/manual/en/function.reset.php">reset</a>&#8221; method is slightly faster than &#8220;<a href="http://www.php.net/manual/en/function.array-values.php">array_values</a>&#8221; ( as seen in code comments ) </p>
]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2009/08/05/accessing-the-first-element-in-associative-php-array/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Screencast of my GSoC Project</title>
		<link>http://mostafa.mosmar.com/blog/2008/09/15/screencast-of-my-gsoc-project/</link>
		<comments>http://mostafa.mosmar.com/blog/2008/09/15/screencast-of-my-gsoc-project/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 01:17:45 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[GSoC]]></category>
		<category><![CDATA[JForms]]></category>
		<category><![CDATA[Screencast]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/2008/09/15/screencast-of-my-gsoc-project/</guid>
		<description><![CDATA[My project for GSoC 2008 was to create a WYSIWYG forms component (Web form editor) that runs on Joomla! 1.5 , This video shows a simple usage scenario ( including an encounter with a bug! ) Links: Development trunk(SVN): http://joomlacode.org/svn/gsoc2008/JForms/trunk/ JForms blog on J! Developer website Latest packaged version P.S : I used CamStudio to [...]]]></description>
			<content:encoded><![CDATA[<p class="english-text" >My project for GSoC 2008 was to create a WYSIWYG forms component (Web form editor) that runs on Joomla! 1.5 , This video shows a simple usage  scenario ( including an encounter with a bug! )</p>
<p class="english-text" ><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/vK3wyoFtCbk&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/vK3wyoFtCbk&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p class="english-text" ><strong>Links:</strong></p>
<p class="english-text" ><strong>Development trunk(SVN):</strong> http://joomlacode.org/svn/gsoc2008/JForms/trunk/</p>
<p class="english-text" ><a href="http://developer.joomla.org/gsoc2008/forms/">JForms blog on J! Developer website</a></p>
<p class="english-text" ><a href="http://mosmar.com/com_jforms_0.5_alpha_rev658.zip ">Latest packaged version</a></p>
<p class="english-text" >P.S : I used <a href="http://camstudio.org/">CamStudio</a> to create this video.</p>
]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2008/09/15/screencast-of-my-gsoc-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web-based WYSIWYG Form designer</title>
		<link>http://mostafa.mosmar.com/blog/2008/04/14/wysiwyg-form-designer/</link>
		<comments>http://mostafa.mosmar.com/blog/2008/04/14/wysiwyg-form-designer/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 22:21:50 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[GSoC]]></category>
		<category><![CDATA[JForms]]></category>
		<category><![CDATA[WYSIWYG]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/2008/04/14/wysiwyg-form-designer/</guid>
		<description><![CDATA[A few days ago I decided to suppress my &#8220;conservative&#8221; stance towards massive Javascript usage and started working on a WYSIWYG editor for HTML Forms, The application resembles drag-and-drop GUI editors, I&#8217;ve spent lot of time in building the codebase to make it as Object oriented as possible. The codebase is simply composed of two [...]]]></description>
			<content:encoded><![CDATA[<p class="english-text" >A few days ago I decided to suppress my &#8220;conservative&#8221; stance towards massive Javascript usage and started working on a WYSIWYG editor for HTML Forms, The application resembles drag-and-drop GUI editors, I&#8217;ve spent lot of time in building the codebase to make it as Object oriented as possible.</p>
<p class="english-text" >The codebase is simply composed of two parts, Core and pluginis &#8220;Elements&#8221;</p>
<p class="english-text" >Each draggable element is handled by a 2 files </p>
<ul class="english-text" >
<li>A javascript file that does the rendering and the event handling &#8220;Events are triggered by the core and passed down to each individual element&#8221;.</li>
<li>A php file that defines what properties the element has, these information are used by the core to generate property page, this file is just meant to hold configuration parameters, no actual coding involved.</li>
</ul>
<p class="english-text" >Adding a new element would just require writing two files and the core handles the rest.</p>
<p class="english-text" >I&#8217;m using <a href="http://www.prototypejs.org">Prototype</a>, <a href="http://script.aculo.us/">script.aculo.us</a> and <a href="http://www.webtoolkit.info/javascript-context-menu.html">Webtoolkit context menu</a>, No true AJAX has been used so far, everything is done on the client side.</p>
<p class="english-text" >Now the question is , what does the end user see?</p>
<ul class="english-text" >
<li>Drag and drop environment</li>
<li>Context menu for each element</li>
<li>Properties for each element</li>
<li>Simple keyboard interaction &#8220;Selected element can be deleted by pressing the (del) button (except textfield and textarea)&#8221;</li>
</ul>
<p class="english-text" >I&#8217;ve tested this on FF2 and IE6.</p>
<p class="english-text" >What I really need to implement right now is the &#8220;Resize&#8221; function</p>
<p class="english-text" >Why don&#8217;t you check <a href="http://mosmar.com/wysiwyg">A demo of the code in action</a></p>
<p class="english-text" >I plan to turn this into a Joomla! forms component soon Insh&#8217;Allah. </p>
<p class="english-text" ><em>Update:</em> My Proposal to Google Summer of Code has been accepted and I&#8217;ll be working on implementing this form editor as a Joomla! 1.5 component, You can find more information about my progress on <a href="http://developer.joomla.org/gsoc2008/forms.html">my GSoC blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2008/04/14/wysiwyg-form-designer/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>It is finally here , Joomla! 1.5</title>
		<link>http://mostafa.mosmar.com/blog/2008/01/22/it-is-finally-here-joomla-15/</link>
		<comments>http://mostafa.mosmar.com/blog/2008/01/22/it-is-finally-here-joomla-15/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 10:21:03 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[1.5]]></category>
		<category><![CDATA[Release]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/2008/01/22/it-is-finally-here-joomla-15/</guid>
		<description><![CDATA[The long waited Joomla! 1.5 has finally hit stable status]]></description>
			<content:encoded><![CDATA[<p class="english-text" >The long waited Joomla! 1.5 has finally hit <a href="http://www.joomla.org/content/view/4488/1/">stable status</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2008/01/22/it-is-finally-here-joomla-15/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arabic , PDF And Joomla!</title>
		<link>http://mostafa.mosmar.com/blog/2007/05/05/arabic-pdf-and-joomla/</link>
		<comments>http://mostafa.mosmar.com/blog/2007/05/05/arabic-pdf-and-joomla/#comments</comments>
		<pubDate>Fri, 04 May 2007 23:20:17 +0000</pubDate>
		<dc:creator>مصطفى</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://mostafa.mosmar.com/blog/2007/05/05/arabic-pdf-and-joomla/</guid>
		<description><![CDATA[Update August 2nd, 2007: I will be releasing this hack in the following few days Insha&#8217;Allah. Update September 4th, 2007: I&#8217;ve released the code on SourceForge you can access it by checking out the CVS there. The project url: http://sourceforge.net/projects/arabic-tcpdf CVS Checkout command cvs -z3 -d:pserver:anonymous@arabic-tcpdf.cvs.sourceforge.net:/cvsroot/arabic-tcpdf co -P artcpdf It is a known fact that [...]]]></description>
			<content:encoded><![CDATA[<p class="english-text" ><strong><em>Update August 2nd, 2007</em></strong>: I will be releasing this hack in the following few days Insha&#8217;Allah.</p>
<p class="english-text" > <strong><em>Update September 4th, 2007</em></strong>: I&#8217;ve released the code on SourceForge you can access it by checking out the CVS there.<br />
The project url: <a href="http://sourceforge.net/projects/arabic-tcpdf">http://sourceforge.net/projects/arabic-tcpdf</a></p>
<p class="english-text" >CVS Checkout command</p>
<div class="english-text"  class='code'>
cvs -z3 -d:pserver:anonymous@arabic-tcpdf.cvs.sourceforge.net:/cvsroot/arabic-tcpdf co -P artcpdf
</div>
<hr />
<p class="english-text" >It is a known fact that Joomla! 1.0.x can export content into pdf format, however, this feature doesn&#8217;t seem to be working well when used to export Arabic content to pdf format, either windows-1256 or UTF-8 encoded.</p>
<p class="english-text" >To address this issue, The guys at the Joomla! core has moved  to TCPDF library to export pdf files, this library has support for images and more importantly UTF-8 which means it can -theoritaclly speaking- be used to handle pretty much ANY langauge, This is true for many Left-To-Right languages, however, For a Right-To-Left language like Arabic the situation is quite different I&#8217;ll try to brief the problem here.<br />
<span id="more-21"></span><br />
First off, Arabic is a complex script language, This means that putting letters side by side is not just enough, A typical Arabic letter has different combining forms based on its context in the word.<br />
For a PDF generator to handle Arabic text correctly it must pre-process the input text and determine which combining form to render &#8220;Shaping&#8221; ,otherwise the text will appear as separated Arabic letters as shown in the following image, So far Joomla! 1.5 PDF engine doesn&#8217;t take that in consideration which means any Arabic text exported by Joomla! will appear as separated letters.</p>
<p class="english-text" ><a href='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf_original.png' title='orignal article'><img src='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf_original.png' alt='orignal article' /></a></p>
<div class="english-text"  class='caption'>Original text as seen in the HTML version of the sample article</div>
<p class="english-text" ><a href='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf1.png' title='PDF output without modifications'><img src='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf1.png' alt='PDF output without modifications' /></a></p>
<div class="english-text"  class='caption'>PDF output of the same article (Note that letters are separated and rendered from left to right),Note that letters are separated and rendered from left to right.
</div>
<p class="english-text" >To tackle this issue I&#8217;m using a class called <a href="http://www.phpclasses.org/browse/package/3192.html">ArGlyphs</a>  by Khaled Al-Shamaa.</p>
<p class="english-text" >Quoting from the project description on phpclasses.org</p>
<blockquote class="english-text"  cite="http://www.phpclasses.org/browse/package/3192.html"><div>
The class takes as input Arabic text encoded using Windows-1256 character set and performs Arabic glyph joining to output a string encoded using UTF-8.
</div>
</blockquote>
<p class="english-text" >So basically this class will fix this shaping problem , I had to modify it a bit to accept UTF-8 without messing it up, I used the phpUTF8 library which is bundled with Joomla! 1.5</p>
<p class="english-text" >Now the output looks like this</p>
<p class="english-text" ><a href='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf2.png' title='PDF after shaping'><img src='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf2.png' alt='PDF after shaping' /></a></p>
<div class="english-text"  class='caption'>
The letters are no longer separated but are still rendered from left to right.
</div>
<p class="english-text" >Which brings us to the second problem,The TCPDF Library only outputs text from Left-To-Right which causes RTL scripts to be displayed in reversed order, simply reversing the string before passing it to the rendering engine won&#8217;t fix this problem, I think FriBidi may fix this but it is not available with every php Installation so I can&#8217;t relay on it to fix this problem for Joomla! ,So I gave it a shot and written my own code (I always like to write my own code ;P), The code I wrote simply breaks down text into pieces based on its UTF-8 range and then reverses the pieces &#8220;runs&#8221; that are identified as RTL  &#8220;like Arabic&#8221; and leaves other runs without modification.</p>
<p class="english-text" ><a href='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf3.png' title='PDF after shaping and RTL’ing'><img src='http://mostafa.mosmar.com/blog/wp-content/uploads/2007/05/pdf3.png' alt='PDF after shaping and RTL’ing' /></a></p>
<div class="english-text"  class='caption'>Output after shaping and RTL&#8217;ing</div>
<p class="english-text" >Letters are correctly shaped &#8220;with minor errors&#8221; and are rendered right to left, however, the lines are reversed , you should be able to read it correctly by starting from the bottom line and proceed upwards,I&#8217;m yet to fix this problem , If you have any suggestions on how to fix this or an easier way of doing the whole thing please let me know, I think there gotta be a better way of doing this.</p>
<p class="english-text" >Edit ( 8/5/2007 ) : I have managed to fix that issue but the code still needs to much clean-up and bug-proofing ,<a href='http://mostafa.mosmar.com/sample.pdf'> here&#8217;s a sample of the output</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mostafa.mosmar.com/blog/2007/05/05/arabic-pdf-and-joomla/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
