<?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>Nimal&#039;s Weblog &#187; PHP</title>
	<atom:link href="http://nimal.info/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://nimal.info/blog</link>
	<description>Nimal blogs here</description>
	<lastBuildDate>Wed, 01 Sep 2010 07:35:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Parse RSS feeds with PHP</title>
		<link>http://nimal.info/blog/2009/parse-rss-feeds-with-php/</link>
		<comments>http://nimal.info/blog/2009/parse-rss-feeds-with-php/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 12:15:04 +0000</pubDate>
		<dc:creator>Nimal</dc:creator>
				<category><![CDATA[Tech Notes]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Feeds]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RSS]]></category>

		<guid isPermaLink="false">http://nimal.info/blog/?p=310</guid>
		<description><![CDATA[RSS feeds are very common today, and at times we want to write a simple script to grab some information from a feed.<p><a href="http://nimal.info/blog/2009/parse-rss-feeds-with-php/">Parse RSS feeds with PHP</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>RSS feeds are very common today, and at times we want to write a simple script to grab some information from a feed.</p>
<p>PHP has got and extensive set of functions that can be used to manipulate XML (RSS feeds or even HTML) files. PHP DOM library is one of the handy libraries that can be used to parse RSS feeds in PHP. DOM (Document Object Model) is a standard way for accessing and manipulating XML documents. XML documents can be represented in tree-structure (a node tree), with the elements, attributes, and text defined as nodes.</p>
<p>Below you can find the script for parsing a standard RSS feeds:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Create a new DOMDocument object</span>
<span style="color: #000088;">$doc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Load the RSS file into the object</span>
<span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://feeds.feedburner.com/talkouttrojans'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Initialize empty array</span>
<span style="color: #000088;">$arrFeeds</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get a list of all the elements with the name 'item'</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$doc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'item'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$itemRSS</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'desc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'link'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'date'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pubDate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arrFeeds</span><span style="color: #339933;">,</span> <span style="color: #000088;">$itemRSS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arrFeeds</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The getElementsByTagName method is used, within the loop of the item nodes, to get the nodeValue for the title, description, link and date tags. The nodeValue is the text within the node. An array is used to store each set of values and each array represents an entry in the big array that holds our structured RSS data. At the end of the script all the data will be hold by the $arrFeeds array, which is well structured and can be used to display or further manipulation.</p>
<p>One drawback of using the DOM library is that it reads the entire XML document into memory, and then we use the functions for manipulating the data. Thus this method is that is not recommended for large XML documents, which would take too much memory to build the model of the document.</p>
<p>Anyway, usually the feeds we are dealing with are of normal size, and this won&#8217;t be an issue at most occasions.</p>
<p><a href="http://nimal.info/blog/2009/parse-rss-feeds-with-php/">Parse RSS feeds with PHP</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nimal.info/blog/2009/parse-rss-feeds-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Text to Image in PHP with GD</title>
		<link>http://nimal.info/blog/2009/text-to-image-in-php-with-gd/</link>
		<comments>http://nimal.info/blog/2009/text-to-image-in-php-with-gd/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 17:03:00 +0000</pubDate>
		<dc:creator>Nimal</dc:creator>
				<category><![CDATA[Tech Notes]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://nimal.info/blog/?p=132</guid>
		<description><![CDATA[This is simple script to demonstrate the capabilities of PHP with the GD library, which provides a lot of image functions that can be useful in many applications.<p><a href="http://nimal.info/blog/2009/text-to-image-in-php-with-gd/">Text to Image in PHP with GD</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This is simple script to demonstrate the capabilities of <a href="../">PHP</a> with the <a href="http://us2.php.net/manual/en/book.image.php"><acronym title="Graphics Draw">GD</acronym> library</a>, which provides a lot of image    functions that can be useful in many applications. GD provides a rich set of functions. For a complete list of these functions, check the <a href="http://us2.php.net/manual/en/ref.image.php">PHP manual</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Text to be converted to image</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Hello World'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Font to use, give accessible path from script</span>
<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./arial.ttf'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Convert HTML entities into ISO-8859-1</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">ENT_NOQUOTES</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ISO-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">160</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">160</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$white</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$black</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create some colors</span>
<span style="color: #990000;">imagefilledrectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">160</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #000088;">$white</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add the text</span>
<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></div></div>

<p>GD can also be used to create and manipulate image files in a variety of different image formats, including <a href="http://us2.php.net/manual/en/function.imagegif.php"><acronym title="Graphic Interchange Format">GIF</acronym></a>, <a href="http://us2.php.net/manual/en/function.imagepng.php"><acronym title="Portable Network Graphics">PNG</acronym></a>,    <a href="http://us2.php.net/manual/en/function.imagejpeg.php"><acronym title="Joint Photographic Experts Group">JPEG</acronym></a>, <a href="http://us2.php.net/manual/en/function.imagewbmp.php"><acronym title="Wireless Bitmap">WBMP</acronym></a>, and <acronym>XPM</acronym>.</p>
<p><em><strong>Limitations:</strong></em></p>
<ul>
<li>Though GD supports Unicode text inputs, it doesn&#8217;t support <strong> </strong><a href="http://en.wikipedia.org/wiki/Complex_text_layout"><strong>complex text rendering</strong></a></li>
<li> Complex Text Rendering is required for properly displaying many language texts, such as the <a title="Arabic alphabet" href="http://en.wikipedia.org/wiki/Arabic_alphabet">Arabic alphabet</a> and scripts of the <a class="mw-redirect" title="Brahmic family" href="http://en.wikipedia.org/wiki/Brahmic_family">Brahmic family</a>, which includes Tamil and many other Indic scripts.</li>
</ul>
<p><em><strong>There is a alternative for this using <a title="Pango" href="http://en.wikipedia.org/wiki/Pango">Pango</a> and <a href="http://cairographics.org/">Cairo</a> in PHP. I&#8217;ll post a detailed update on that in my next post.</strong></em></p>
<p><a href="http://nimal.info/blog/2009/text-to-image-in-php-with-gd/">Text to Image in PHP with GD</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nimal.info/blog/2009/text-to-image-in-php-with-gd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Activate Oracle on XAMPP for Windows</title>
		<link>http://nimal.info/blog/2009/activate-oracle-on-xampp-for-windows/</link>
		<comments>http://nimal.info/blog/2009/activate-oracle-on-xampp-for-windows/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 04:30:00 +0000</pubDate>
		<dc:creator>Nimal</dc:creator>
				<category><![CDATA[Tech Notes]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XAMPP]]></category>

		<guid isPermaLink="false">http://nimal.info/blog/?p=131</guid>
		<description><![CDATA[PHP has got the OCI8 extension, which provides Oracle connectivity to PHP application, and OCI8 uses Oracle Instant Client Package to get Oracle specific functions.<p><a href="http://nimal.info/blog/2009/activate-oracle-on-xampp-for-windows/">Activate Oracle on XAMPP for Windows</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;" href="http://1.bp.blogspot.com/_QU2k3YoKpNc/SpBSHpW4wRI/AAAAAAAACyY/FU8GSbpeVK0/s1600-h/php-med-trans-light.gif"><img src="http://1.bp.blogspot.com/_QU2k3YoKpNc/SpBSHpW4wRI/AAAAAAAACyY/FU8GSbpeVK0/s320/php-med-trans-light.gif" border="0" alt="" /></a>With the default installation of <a href="http://www.apachefriends.org/en/xampp-windows.html">XAMPP for Windows</a>, we don&#8217;t get <a href="http://www.php.net/">PHP</a> <a href="http://www.oracle.com/">Oracle</a> connectivity enabled. This can be enabled easily when you need to connect to a <a href="http://en.wikipedia.org/wiki/Oracle_Database">Oracle Database</a> from your PHP application/script. <a href="http://en.wikipedia.org/wiki/PHP">PHP</a> has got the <a href="http://www.php.net/oci8">OCI8</a> extension, which provides Oracle connectivity to PHP application, and OCI8 uses <a href="http://otn.oracle.com/tech/oci/instantclient/instantclient.html">Oracle Instant Client Package</a> to get Oracle specific functions.<br />
<a style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" href="http://2.bp.blogspot.com/_QU2k3YoKpNc/SpBSNPGLzAI/AAAAAAAACyg/yYTx4wuz39E/s1600-h/database_clr.gif"><img src="http://2.bp.blogspot.com/_QU2k3YoKpNc/SpBSNPGLzAI/AAAAAAAACyg/yYTx4wuz39E/s320/database_clr.gif" border="0" alt="" /></a><br />
I had the need to connect to a Oracle Database from a PHP script in one of my recent projects, the following is what I did to enable Oracle connectivity in XAMPP for Windows.</p>
<ol>
<li>In your XAMPP Start Page, go to <strong>phpinfo, </strong>look for string <strong>oci8</strong>. If string found it indicate that connection to oracle is available, otherwise to activate connection do the following steps:</li>
<li>Open the currently used <strong>php.ini</strong> file by looking at the <strong>phpinfo</strong>, from the XAMPP folder.</li>
<li>Find string <strong>;extension=php_oci8.dll</strong>. Remove the semicolon (<strong>;</strong>) ahead of the string to activate the oracle extension.</li>
<li>Save the <strong>php.ini </strong>file.</li>
<li>Download the &#8220;Instant Client Package &#8211; Basic&#8221; for Windows from the <a href="http://otn.oracle.com/tech/oci/instantclient/instantclient.html" target="_blank">OTN Instant Client page</a>. Unzip it to c:\instantclient_11_1</li>
<li>Edit the PATH environment setting and add c:\instantclient_11_1 before any other Oracle directories. For example, on Windows XP, follow <strong>Start -&gt; Control Panel -&gt; System -&gt; Advanced -&gt; Environment Variables</strong> and edit PATH in the System variables list.</li>
<li>Set desired Oracle globalization language environment variables such as NLS_LANG. If nothing is set, a default local environment will be assumed. See <a href="http://www.oracle.com/technology/tech/php/pdf/globalizing_oracle_php_applications.pdf" target="_blank">An Overview on Globalizing Oracle PHP Applications</a> for more details.</li>
<li>Unset Oracle variables such as ORACLE_HOME and ORACLE_SID, which are unnecessary with Instant Client (if they are set previously).</li>
<li>Restart XAMPP (or Start if its not already started).</li>
<li>To make sure that connection to oracle database has successfully activated, go to phpinfo. Find string: oci8. If found, then XAMPP can now communicate with Oracle Database.</li>
</ol>
<p>The steps to do the same in a Linux box are almost similar, except there you will use the Linux versions of the packages and setting PATH variables would be different.</p>
<p>You can ping me back with a comment if you run into any issues, I might be able to help you or I can learn from you.</p>
<p><strong><em>Reference:</em></strong></p>
<ul>
<li><a href="http://www.oracle.com/technology/pub/notes/technote_php_instant.html" target="_blank">http://www.oracle.com/technology/pub/notes/technote_php_instant.html</a></li>
</ul>
<p><a href="http://nimal.info/blog/2009/activate-oracle-on-xampp-for-windows/">Activate Oracle on XAMPP for Windows</a> is a post from: <a href="http://nimal.info/blog">Nimal&#039;s Weblog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nimal.info/blog/2009/activate-oracle-on-xampp-for-windows/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
