<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0"><channel><title>Quick PHP Code Tips and Examples</title><link>http://phpcode.mypapit.net</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/phpcode" /><description>PHP Programming Tips, Tutorials and Source Code Examples for newbie</description><language>en</language><generator>http://wordpress.org/?v=2.5.1</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/phpcode" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="phpcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by-nc-sa/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><item><title>Detect Alphabet only string with ctype_alpha</title><link>http://phpcode.mypapit.net/detect-alphabet-only-string-with-ctype_alpha/50/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Wed, 04 Jun 2008 20:07:20 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/?p=50</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>There are times when you need a function that can detect strings which contains onlyalphabetic characters. While <a href="http://my2.php.net/manual/en/function.is-numeric.php">is_numeric</a> can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings.</p>
<p>However, you can still test for alphabetic string using<a href="http://my2.php.net/ctype_alpha"> ctype_alpha() </a>function. Example usage :</p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#40;</span>ctype_alpha<span style="color:#006600; font-weight:bold;">&#40;</span>$testcase<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"The string $testcase consists of all letters.<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> else <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; echo <span style="color:#CC0000;">"The string $testcase does not consist of all letters.<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Good luck, and happy coding.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/MU_xmszNQjxN335qLV4YtkIoH3A/0/da"><img src="http://feedads.g.doubleclick.net/~a/MU_xmszNQjxN335qLV4YtkIoH3A/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MU_xmszNQjxN335qLV4YtkIoH3A/1/da"><img src="http://feedads.g.doubleclick.net/~a/MU_xmszNQjxN335qLV4YtkIoH3A/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>There are times when you need a function that can detect strings which contains onlyalphabetic characters. While is_numeric can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings.
However, you can still test for alphabetic string using ctype_alpha() function. Example usage :
PLAIN TEXT
CODE:




if [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/detect-alphabet-only-string-with-ctype_alpha/50/feed/</wfw:commentRss></item><item><title>How to Truncate table in SQLite database</title><link>http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Wed, 04 Jun 2008 03:09:21 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/?p=49</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I found out that truncating  SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line</p>
<div class="igBar"><span id="lcode-5"><a href="#" onclick="javascript:showPlainTxt('code-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-5">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sqlite your_database.<span style="">db</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sqlite&amp;gt; DELETE FROM some_table; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>after that, dont forget to execute VACUUM to compact the database :</p>
<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-6">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">sqlite&amp;gt; VACUUM; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>

<p><a href="http://feedads.g.doubleclick.net/~a/scwCTsVZsf-59l2nwm2crBnedm4/0/da"><img src="http://feedads.g.doubleclick.net/~a/scwCTsVZsf-59l2nwm2crBnedm4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/scwCTsVZsf-59l2nwm2crBnedm4/1/da"><img src="http://feedads.g.doubleclick.net/~a/scwCTsVZsf-59l2nwm2crBnedm4/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>I found out that truncating  SQLite database is a little bit different from its MySQL counterpart. Here's how to truncate SQLite database from command line
PLAIN TEXT
CODE:




sqlite your_database.db


sqlite&amp;#38;gt; DELETE FROM some_table; 






after that, dont forget to execute VACUUM to compact the database :
PLAIN TEXT
CODE:




sqlite&amp;#38;gt; VACUUM;</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/how-to-truncate-table-in-sqlite-database/49/feed/</wfw:commentRss></item><item><title>Quick PHP Code is back!</title><link>http://phpcode.mypapit.net/quick-php-code-is-back/48/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Tue, 29 Apr 2008 21:25:53 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/?p=48</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Quick PHP Code is back! So appology for the delays caused due to some unavoidable circumstances. We are no back!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/WnVJ50GbmOvnU4ClfijKQAWk0iM/0/da"><img src="http://feedads.g.doubleclick.net/~a/WnVJ50GbmOvnU4ClfijKQAWk0iM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WnVJ50GbmOvnU4ClfijKQAWk0iM/1/da"><img src="http://feedads.g.doubleclick.net/~a/WnVJ50GbmOvnU4ClfijKQAWk0iM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Quick PHP Code is back! So appology for the delays caused due to some unavoidable circumstances. We are no back!</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/quick-php-code-is-back/48/feed/</wfw:commentRss></item><item><title>How to solve file_get_contents and file() PHP errors</title><link>http://phpcode.mypapit.net/how-to-solve-file_get_contents-and-file-php-errors/45/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Thu, 17 May 2007 18:47:03 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/quick-tips/how-to-solve-file_get_contents-and-file-php-errors/45/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p><a href="http://my2.php.net/file_get_contents">file_get_contents()</a> is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts.</p>
<p>However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws out an error which can render the whole web application useless in that particular web server.</p>
<p>To remedy this, you can replace file_get_contents() function with PHP cURL calls. Here's how you can do this.</p>
<p><strong>Before</strong><br />
<a href="http://phpcode.mypapit.net/demo/fileget.txt">file_get_contents</a></p>
<p><strong>After</strong><br />
<a href="http://phpcode.mypapit.net/demo/curl.txt">CURL solution</a></p>
<p>Although the cURL version seems to be a little bit longer, it is guaranteed to work across servers which place restriction on file_get_contents() and file() function. The use of <a href="http://phpcode.mypapit.net/php-class/libcurlemu-a-drop-in-replacement-for-php-curl-library/17/">libcurlemu</a> ensures that the script can work even on a server which doesn't have the PHP CURL extension, which makes this a universal solution for retrieving remote web content from PHP application.</p>
<p>Tags: <a href="http://technorati.com/tag/curl" rel="tag">curl</a>, <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/remote" rel="tag">remote</a>, <a href="http://technorati.com/tag/security" rel="tag">security</a>, <a href="http://technorati.com/tag/php+scripts" rel="tag">php scripts</a>, <a href="http://technorati.com/tag/web+hosting" rel="tag">web hosting</a>, <a href="http://technorati.com/tag/web" rel="tag">web</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/3DeVsz_C63e-pq4YmVke8sKIaAM/0/da"><img src="http://feedads.g.doubleclick.net/~a/3DeVsz_C63e-pq4YmVke8sKIaAM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3DeVsz_C63e-pq4YmVke8sKIaAM/1/da"><img src="http://feedads.g.doubleclick.net/~a/3DeVsz_C63e-pq4YmVke8sKIaAM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>file_get_contents() is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts.
However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/how-to-solve-file_get_contents-and-file-php-errors/45/feed/</wfw:commentRss></item><item><title>SQL Injection Examples (Cheatsheet)</title><link>http://phpcode.mypapit.net/sql-injection-examples-cheatsheet/47/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Wed, 16 May 2007 04:19:05 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/security/sql-injection-examples-cheatsheet/47/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>If you're writing web application that has access to database, then you should be aware that those application are susceptible to <a href="http://en.wikipedia.org/wiki/SQL_injection">SQL Injection attacks</a> which leave information stored in your database vulnerable from a malicious cracker.</p>
<p>This can led attacker to access private areas in your web application, steal sensitive information, erase your database or alter certain information in the database for his own gain. Therefore it is prudent to safeguard your web application by <a href="http://phpcode.mypapit.net/security/sanitize-php-variables-with-owasp-php-filter/6/">filtering unsafe input variables</a> before inputting them into SQL statements.</p>
<p><strong>How crackers perform SQL Injection</strong><br />
Here is a list of common <a href="http://ferruh.mavituna.com/makale/sql-injection-cheatsheet/#AboutMySQLandPHP">SQL injection technique</a> employed by malicious users across the internet. </p>
<p>Another good read that I suggest is <a href="http://www.unixwiz.net/techtips/sql-injection.html">SQL Injection by examples</a> which provide great explanation of how SQL Injection attacks are performed. </p>
<p>Tags: <a href="http://technorati.com/tag/sql" rel="tag">sql</a>, <a href="http://technorati.com/tag/mysql" rel="tag">mysql</a>, <a href="http://technorati.com/tag/injection" rel="tag">injection</a>, <a href="http://technorati.com/tag/security" rel="tag">security</a>, <a href="http://technorati.com/tag/sqlite" rel="tag">sqlite</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/raGavnnpRuy8pH1lLtC7eSyxErg/0/da"><img src="http://feedads.g.doubleclick.net/~a/raGavnnpRuy8pH1lLtC7eSyxErg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/raGavnnpRuy8pH1lLtC7eSyxErg/1/da"><img src="http://feedads.g.doubleclick.net/~a/raGavnnpRuy8pH1lLtC7eSyxErg/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>If you're writing web application that has access to database, then you should be aware that those application are susceptible to SQL Injection attacks which leave information stored in your database vulnerable from a malicious cracker.
This can led attacker to access private areas in your web application, steal sensitive information, erase your database or alter [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/sql-injection-examples-cheatsheet/47/feed/</wfw:commentRss></item><item><title>Naive Bayesian Tutorial in PHP</title><link>http://phpcode.mypapit.net/naive-bayesian-tutorial-in-php/41/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Tue, 15 May 2007 21:45:18 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/php-class/naive-bayesian-tutorial-in-php/41/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>The practitioner of artificial intelligence and machine learning algorithm will recognize<a href="http://en.wikipedia.org/wiki/Naive_Bayes_classifier"> Naive Bayesian</a> as one of the technique use to construct intelligent web application. Naive Bayesian is widely use as an intelligent classifier utilized to automatically classfies data based on statistical probability.</p>
<p>Among the immediate use of Naive Bayesian technique is the classification of (spam) emails, medical diagnosis dan data pattern identification.</p>
<p>Naive Bayesian is able to 'learn' from experience by training it with sample data set to categorized certain type data. </p>
<p><strong>Excellent Naive Bayesian Tutorial</strong><br />
I found an excellent source of PHP Naive Bayesian classifier tutorial written specifically for those who has no background experience in the field of AI and Data Mining :</p>
<ol>
<li><a href="http://www.devshed.com/c/a/PHP/Implement-Bayesian-inference-using-PHP-Part-1/">Implement Bayesian inference using PHP, Part 1 </a></li>
<li><a href="http://www.ibm.com/developerworks/web/library/wa-bayes2/">Implement Bayesian inference using PHP, Part 2 </a></li>
<li><a href="http://www-128.ibm.com/developerworks/web/library/wa-bayes3/">Implement Bayesian inference using PHP, Part 3</a></li>
</ol>
<p><strong>Other PHP Naive Bayesian Library </strong><br />
Here is a few great naive bayesian implementation written in PHP</p>
<ol>
<li><a href="http://xhtml.net/php/PHPNaiveBayesianFilter">PHP Naive Bayesian Filter</a></li>
<li><a href="http://nasauber.de/programme/b8/index.php.en">b8 (formerly bayes-php)</a></li>
</ol>
<p>Tags: <a href="http://technorati.com/tag/naive+bayesian" rel="tag">naive bayesian</a>, <a href="http://technorati.com/tag/bayes" rel="tag">bayes</a>, <a href="http://technorati.com/tag/bayesian" rel="tag">bayesian</a>, <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/artificial+intelligence" rel="tag">artificial intelligence</a>, <a href="http://technorati.com/tag/ai" rel="tag">ai</a>, <a href="http://technorati.com/tag/scripts" rel="tag">scripts</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/oTI-9A4leYIYjhMfcqAKdmdqFjo/0/da"><img src="http://feedads.g.doubleclick.net/~a/oTI-9A4leYIYjhMfcqAKdmdqFjo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/oTI-9A4leYIYjhMfcqAKdmdqFjo/1/da"><img src="http://feedads.g.doubleclick.net/~a/oTI-9A4leYIYjhMfcqAKdmdqFjo/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>The practitioner of artificial intelligence and machine learning algorithm will recognize Naive Bayesian as one of the technique use to construct intelligent web application. Naive Bayesian is widely use as an intelligent classifier utilized to automatically classfies data based on statistical probability.
Among the immediate use of Naive Bayesian technique is the classification of (spam) emails, [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/naive-bayesian-tutorial-in-php/41/feed/</wfw:commentRss></item><item><title>Detect ip location, operating system and browser using PHP Detector Library</title><link>http://phpcode.mypapit.net/detect-ip-location-operating-system-and-browser-using-php-detector-library/46/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Mon, 14 May 2007 19:40:17 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/library/detect-ip-location-operating-system-and-browser-using-php-detector-library/46/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>I've decided to share my <a href="http://phpcode.mypapit.net/demo/detector/detector.zip">PHP Detector library</a> to the public which I've coded somewhere around 2006. The library does wonders in detecting IP address geo-location, operating system and the type of browser used based on its user-agent information. </p>
<p>The ip address->geo-location information is provided for free from <a href="http://showip.fakap.net/">ShowIP fakap webservice</a>.</p>
<p>The library is handy for for creating web application which serve content depending on users location and type of operating system/browser that he use or for creating web application that collect web surfers statistical data.</p>
<p>Here's how to use Detector library :</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'detector.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$dip</span> = <span style="color:#000000; font-weight:bold;">&amp;new</span> Detector<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"REMOTE_ADDR"</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">"HTTP_USER_AGENT"</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"$dip-&gt;town"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"$dip-&gt;state, $dip-&gt;ccode,$dip-&gt;town, ($dip-&gt;ipaddress) "</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"using : $dip-&gt;browser $dip-&gt;browser_version on $dip-&gt;os $dip-&gt;os_version"</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The live demo of Detector library in action can be viewed here : <a href="http://phpcode.mypapit.net/demo/detector/">Detector Library demo</a>.</p>
<p><strong>Requirements</strong></p>
<ol>
<li>Requires PHP 4.4.0 or 5.0.x</li>
<li>Requires php cURL extension installed, <a href="http://phpcode.mypapit.net/php-class/libcurlemu-a-drop-in-replacement-for-php-curl-library/17/">please refer here for workaround </a>if your server doesn't have PHP cURL extension installed</li>
</ol>
<p><strong>License</strong><br />
Detector library is licensed under <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0</a>, and can be modified and used in commercial application as long as you share the modified source code with the public.</p>
<p>Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/php+library" rel="tag">php library</a>, <a href="http://technorati.com/tag/library" rel="tag">library</a>, <a href="http://technorati.com/tag/user-agent" rel="tag">user-agent</a>, <a href="http://technorati.com/tag/browsers" rel="tag">browsers</a>, <a href="http://technorati.com/tag/detector" rel="tag">detector</a>, <a href="http://technorati.com/tag/snippets" rel="tag">snippets</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/gp0VhFZOnWEl_G4dMOBs8Qp1tM8/0/da"><img src="http://feedads.g.doubleclick.net/~a/gp0VhFZOnWEl_G4dMOBs8Qp1tM8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/gp0VhFZOnWEl_G4dMOBs8Qp1tM8/1/da"><img src="http://feedads.g.doubleclick.net/~a/gp0VhFZOnWEl_G4dMOBs8Qp1tM8/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>I've decided to share my PHP Detector library to the public which I've coded somewhere around 2006. The library does wonders in detecting IP address geo-location, operating system and the type of browser used based on its user-agent information. 
The ip address-&gt;geo-location information is provided for free from ShowIP fakap webservice.
The library is handy for [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/detect-ip-location-operating-system-and-browser-using-php-detector-library/46/feed/</wfw:commentRss></item><item><title>How to send e-mail with Attachment with PHP Scripts</title><link>http://phpcode.mypapit.net/how-to-send-e-mail-with-attachment-with-php-scripts/43/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Mon, 14 May 2007 17:41:39 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/php-class/how-to-send-e-mail-with-attachment-with-php-scripts/43/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Here's how to send an email with attachment using PHP scripts (via <a href="http://phpmailer.sourceforge.net/">PHPMailer class</a>).</p>
<div class="igBar"><span id="lcode-10"><a href="#" onclick="javascript:showPlainTxt('code-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-10">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">require<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"phpmailer/class.phpmailer.php"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//****</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//PLEASE CHANGE THE SETTINGS HERE !!!!</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//change settings here</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$your_email = <span style="color:#CC0000;">"info@example.com"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$your_smtp = <span style="color:#CC0000;">"mail.example.com"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$your_smtp_user = <span style="color:#CC0000;">"info@example.com"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$your_smtp_pass = <span style="color:#CC0000;">"example_password"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$your_website = <span style="color:#CC0000;">"http://example.com"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//****</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//get contact form details</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$name = $_POST<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">'name'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$email = $_POST<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">'email'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$url = $_POST<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">'url'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$comments = $_POST<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">'comments'</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$response=<span style="color:#CC0000;">"Name: $name<span style="color:#000099; font-weight:bold;">\n</span>Contents:<span style="color:#000099; font-weight:bold;">\n</span>$comments<span style="color:#000099; font-weight:bold;">\n</span>"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail = new PHPmailer<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail = $mail-&gt;<span style="">SetLanguage</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"en"</span>, <span style="color:#CC0000;">"phpmailer/language"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">From</span> = $your_email;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">FromName</span> = $your_website;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Host</span> = $your_smtp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Mailer</span>&nbsp; &nbsp;= <span style="color:#CC0000;">"smtp"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Password</span> = $your_smtp_pass;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Username</span> = $your_smtp_user;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Subject</span> = <span style="color:#CC0000;">"$your_website feedback"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">SMTPAuth</span>&nbsp; =&nbsp; <span style="color:#CC0000;">"true"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">Body</span> = $response;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">AddAddress</span><span style="color:#006600; font-weight:bold;">&#40;</span>$your_email,<span style="color:#CC0000;">"$your_website admin"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">AddReplyTo</span><span style="color:#006600; font-weight:bold;">&#40;</span>$email,$name<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">AddAttachment</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"picture.png"</span>,<span style="color:#CC0000;">"picture"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"&lt;p&gt;Thanks for your feedback, &lt;em&gt;$name&lt;/em&gt;! We will contact you soon!&lt;/p&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#40;</span>!$mail-&gt;<span style="">Send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">echo <span style="color:#CC0000;">"&lt;p&gt;There was an error in sending mail, please try again at a later time&lt;/p&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">ClearAddresses</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$mail-&gt;<span style="">ClearAttachments</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>the key function of this script is $mail->AddAttachment("picture.png","picture.png");, where you can add any file as email attachments from your script.</p>
<p>Hopefully this example will help you to create a useful and flexible mail sending php scripts</p>
<p>Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/email" rel="tag">email</a>, <a href="http://technorati.com/tag/emails" rel="tag">emails</a>, <a href="http://technorati.com/tag/mail" rel="tag">mail</a>, <a href="http://technorati.com/tag/e-mails" rel="tag">e-mails</a>, <a href="http://technorati.com/tag/programming" rel="tag">programming</a>, <a href="http://technorati.com/tag/php+scripts" rel="tag"> php scripts</a>, <a href="http://technorati.com/tag/scripts" rel="tag"> scripts</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/7Mc8kg6UlDhk2ulXuvP3_wB3IC0/0/da"><img src="http://feedads.g.doubleclick.net/~a/7Mc8kg6UlDhk2ulXuvP3_wB3IC0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7Mc8kg6UlDhk2ulXuvP3_wB3IC0/1/da"><img src="http://feedads.g.doubleclick.net/~a/7Mc8kg6UlDhk2ulXuvP3_wB3IC0/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Here's how to send an email with attachment using PHP scripts (via PHPMailer class).
PLAIN TEXT
CODE:




require&amp;#40;"phpmailer/class.phpmailer.php"&amp;#41;;


//****


//PLEASE CHANGE THE SETTINGS HERE !!!!


//change settings here


$your_email = "info@example.com";


$your_smtp = "mail.example.com";


$your_smtp_user = "info@example.com";


$your_smtp_pass = "example_password";


$your_website = "http://example.com";


//****


//get contact form details


$name = $_POST&amp;#91;'name'&amp;#93;;


$email = $_POST&amp;#91;'email'&amp;#93;;


$url = $_POST&amp;#91;'url'&amp;#93;;


$comments = $_POST&amp;#91;'comments'&amp;#93;;


$response="Name: $name\nContents:\n$comments\n";


$mail = new PHPmailer&amp;#40;&amp;#41;;


$mail = $mail-&amp;#62;SetLanguage&amp;#40;"en", "phpmailer/language"&amp;#41;;


$mail-&amp;#62;From = $your_email;


$mail-&amp;#62;FromName = $your_website;


$mail-&amp;#62;Host = [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/how-to-send-e-mail-with-attachment-with-php-scripts/43/feed/</wfw:commentRss></item><item><title>PHP: Currency Exchange using XML-RPC client</title><link>http://phpcode.mypapit.net/php-get-currency-exchange-using-xml-rpc/39/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Thu, 10 May 2007 10:08:39 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/web-api/xml-rpc/php-get-currency-exchange-using-xml-rpc/39/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>This is an example PHP code I wrote to demonstrate how to connect to <a href="http://foxrate.org">Foxrate Currency Exchange</a> server and retrieve the latest exchange rate.</p>
<p>The example uses <a href="http://scripts.incutio.com/xmlrpc/">The Incutio XML-RPC for PHP</a> library. Please visit refer to <a href="http://scripts.incutio.com/xmlrpc/manual.php">Incutio XML-RPC Library Manual</a> for further in-depth reference.</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">require</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'IXR.inc.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// connect to foxrate.org currency exchange server</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$client</span> = <span style="color:#000000; font-weight:bold;">new</span> IXR_Client<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'http://foxrate.org/rpc/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//make the currency exchange</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'foxrate.currencyConvert'</span>, <span style="color:#FF0000;">'USD'</span>, <span style="color:#FF0000;">'GBP'</span>,<span style="color:#CC66CC;color:#800000;">1000</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/die"><span style="color:#000066;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Error detected - '</span>.<span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">getErrorCode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">' : '</span>.<span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">getErrorMessage</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$response</span> = <span style="color:#0000FF;">$client</span>-&gt;<span style="color:#006600;">getResponse</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"USD1000&nbsp; is currently equal to GBP "</span> . <span style="color:#0000FF;">$response</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'amount'</span><span style="color:#006600; font-weight:bold;">&#93;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The demo shows you how to get the current value of USD 1000  in British Pound (GBP). Hopefully this example will be useful for you to build a working currency exchage webapp using <a href="http://foxrate.org">foxrate.org api</a></p>
<p>Download the sample code here : <a href="http://phpcode.mypapit.net/dld/foxrate_rpc_1.zip">foxrate_rpc_1.zip</a></p>
<p>Tags: <a href="http://technorati.com/tag/xmlrpc" rel="tag">xmlrpc</a>, <a href="http://technorati.com/tag/xml-rpc" rel="tag">xml-rpc</a>, <a href="http://technorati.com/tag/foxrate" rel="tag">foxrate</a>, <a href="http://technorati.com/tag/currency+exchange" rel="tag">currency exchange</a>, <a href="http://technorati.com/tag/foreign+exchange" rel="tag"> foreign exchange</a>, <a href="http://technorati.com/tag/web+api" rel="tag">web api</a>, <a href="http://technorati.com/tag/rpc" rel="tag"> rpc</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/Vb_o-xiO7Re8m5M1O1-wHeiSLlo/0/da"><img src="http://feedads.g.doubleclick.net/~a/Vb_o-xiO7Re8m5M1O1-wHeiSLlo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Vb_o-xiO7Re8m5M1O1-wHeiSLlo/1/da"><img src="http://feedads.g.doubleclick.net/~a/Vb_o-xiO7Re8m5M1O1-wHeiSLlo/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>This is an example PHP code I wrote to demonstrate how to connect to Foxrate Currency Exchange server and retrieve the latest exchange rate.
The example uses The Incutio XML-RPC for PHP library. Please visit refer to Incutio XML-RPC Library Manual for further in-depth reference.
PLAIN TEXT
PHP:




require&amp;#40;'IXR.inc.php'&amp;#41;;


&amp;#160;


// connect to foxrate.org currency exchange server


$client = new IXR_Client&amp;#40;'http://foxrate.org/rpc/'&amp;#41;;


&amp;#160;


//make the [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/php-get-currency-exchange-using-xml-rpc/39/feed/</wfw:commentRss></item><item><title>OpenTracker - Lean and mean PHP Bittorrent Tracker</title><link>http://phpcode.mypapit.net/opentracker-lean-and-mean-php-bittorrent-tracker/38/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Wed, 09 May 2007 20:48:06 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/scripts/opentracker-lean-and-mean-php-bittorrent-tracker/38/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Opentracker is the most simple php bittorrent tracker that I came across. It only requires a single MySQL table to function and it is a fully compliant bittorrent tracker <a href="http://bitconjurer.org/BitTorrent/index.html">as outlined by Bram Cohen</a>.</p>
<p>I've included Opentracker in this blog because of its simplicity that made it easy to be use as a reference implementation for your own home-brew tracker. </p>
<p><strong>Download Opentracker</strong></p>
<ol>
<li><a href="http://phpcode.mypapit.net/demo/opentracker.zip">opentracker.zip (local)</a></li>
<li><a href="http://www.whitsoftdev.com/files/opentracker.zip">opentracker.zip (mirror)</a></li>
</ol>
<p><strong>Important Notice</strong> Due remember that MySQL based bittorrent trackers are known to use many connections at the same time, and may cause your database server to choke in a shared hosting environment. You've been warned!</p>
<p>Tags: <a href="http://technorati.com/tag/bittorrent" rel="tag">bittorrent</a>, <a href="http://technorati.com/tag/opentracker" rel="tag">opentracker</a>, <a href="http://technorati.com/tag/torrent" rel="tag">torrent</a>, <a href="http://technorati.com/tag/torrents" rel="tag">torrents</a>, <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/php+scripts" rel="tag">php scripts</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/1faV9NtJxGZ6R_JT5GQoQyFVMQY/0/da"><img src="http://feedads.g.doubleclick.net/~a/1faV9NtJxGZ6R_JT5GQoQyFVMQY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/1faV9NtJxGZ6R_JT5GQoQyFVMQY/1/da"><img src="http://feedads.g.doubleclick.net/~a/1faV9NtJxGZ6R_JT5GQoQyFVMQY/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Opentracker is the most simple php bittorrent tracker that I came across. It only requires a single MySQL table to function and it is a fully compliant bittorrent tracker as outlined by Bram Cohen.
I've included Opentracker in this blog because of its simplicity that made it easy to be use as a reference implementation for [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/opentracker-lean-and-mean-php-bittorrent-tracker/38/feed/</wfw:commentRss></item><item><title>Spam Protected Contact Form example  (using Akismet)</title><link>http://phpcode.mypapit.net/spam-protected-contact-form-example-using-akismet/36/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Wed, 09 May 2007 03:07:44 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/general/spam-protected-contact-form-example-using-akismet/36/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>This is an example of an enhanced contact form <a href="http://phpcode.mypapit.net/example/simple-contact-form-example-php/30/">previously featured here</a> and <a href="http://phpcode.mypapit.net/php-class/sending-mail-using-smtp-with-phpmailer/26/">here</a> .  I've improved the contact form example to include <a href="http://phpcode.mypapit.net/php-class/integrate-akismet-anti-spam-service-in-php-scripts/22/">Akismet spam protection</a> in order to make it more resistant to spam attack.</p>
<p><strong>Demonstration</strong></p>
<p><a href="http://phpcode.mypapit.net/demo/plain_akismet/"><img src='http://phpcode.mypapit.net/wp-content/uploads/2007/05/plain_akismet.jpg' alt='plain_akismet.jpg' /></a></p>
<p><strong>The example includes</strong> :</p>
<ul>
<li>PHPMailer class for sending mail through your own SMTP server</li>
<li>Akismet Anti-spam class</li>
<li>Table-less contact form</li>
</ul>
<p>Feel free to download the example to be used in your own application : <a href="http://phpcode.mypapit.net/demo/plain_akismet/plain_akismet.zip">plain_akismet.zip</a></p>
<p>Tags: <a href="http://technorati.com/tag/contact+form" rel="tag">contact form</a>, <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/php4" rel="tag">php4</a>, <a href="http://technorati.com/tag/akismet" rel="tag">akismet</a>, <a href="http://technorati.com/tag/antispam" rel="tag">antispam</a>, <a href="http://technorati.com/tag/anti-spam" rel="tag">anti-spam</a>, <a href="http://technorati.com/tag/example" rel="tag">example</a>, <a href="http://technorati.com/tag/coding" rel="tag">coding</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/UA57uOrLm5Bt9Ka2_Dy0dMQ86sM/0/da"><img src="http://feedads.g.doubleclick.net/~a/UA57uOrLm5Bt9Ka2_Dy0dMQ86sM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UA57uOrLm5Bt9Ka2_Dy0dMQ86sM/1/da"><img src="http://feedads.g.doubleclick.net/~a/UA57uOrLm5Bt9Ka2_Dy0dMQ86sM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>This is an example of an enhanced contact form previously featured here and here .  I've improved the contact form example to include Akismet spam protection in order to make it more resistant to spam attack.
Demonstration

The example includes :

PHPMailer class for sending mail through your own SMTP server
Akismet Anti-spam class
Table-less contact form

Feel free to [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/spam-protected-contact-form-example-using-akismet/36/feed/</wfw:commentRss></item><item><title>How to switch to PHP5 in Cpanel based web hosting</title><link>http://phpcode.mypapit.net/how-to-switch-to-php5-in-cpanel-based-web-hosting/35/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Tue, 08 May 2007 09:33:27 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/general/how-to-switch-to-php5-in-cpanel-based-web-hosting/35/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Some web hosting provider such as <a href="http://e-ruang.com/">e-ruang</a> offers choices of using PHP4 or or PHP5 in their hosting. To avoid conflict with existing scripts, they will usually offer PHP 4 by default.</p>
<p>But for obvious reasons, you may want to use PHP5 as it supports more functionalities and more robust than PHP4. To enable PHP5 for your account, you need to create a .htaccess file containing :</p>
<div class="igBar"><span id="lcode-14"><a href="#" onclick="javascript:showPlainTxt('code-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-14">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">AddHandler application/x-httpd-php5 .<span style="">php</span> .<span style="">php4</span> .<span style="">php3</span> .<span style="">phtml</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Save the .htaccess file, and upload it to the root directory of your server.</p>
<p>Then upload a php file containing <a href="http://phpcode.mypapit.net/snippets/phpinfo-get-info-about-your-php-installation/4/">phpinfo() function</a>  to test whether PHP5 has been enabled or not. If the modification has not been successful then you should contact your web hosting provider and ask about the appropriate way to activate PHP5 functionality.</p>
<p>Tags: <a href="http://technorati.com/tag/php5" rel="tag">php5</a>, <a href="http://technorati.com/tag/php" rel="tag"> php</a>, <a href="http://technorati.com/tag/web+hosting" rel="tag">web hosting</a>, <a href="http://technorati.com/tag/hosting" rel="tag"> hosting</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/SsiDArU69XTBBdrde8z-1Lz0CUk/0/da"><img src="http://feedads.g.doubleclick.net/~a/SsiDArU69XTBBdrde8z-1Lz0CUk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SsiDArU69XTBBdrde8z-1Lz0CUk/1/da"><img src="http://feedads.g.doubleclick.net/~a/SsiDArU69XTBBdrde8z-1Lz0CUk/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Some web hosting provider such as e-ruang offers choices of using PHP4 or or PHP5 in their hosting. To avoid conflict with existing scripts, they will usually offer PHP 4 by default.
But for obvious reasons, you may want to use PHP5 as it supports more functionalities and more robust than PHP4. To enable PHP5 for [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/how-to-switch-to-php5-in-cpanel-based-web-hosting/35/feed/</wfw:commentRss></item><item><title>Using SQLite in PHP 5</title><link>http://phpcode.mypapit.net/using-sqlite-in-php-5/34/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Tue, 08 May 2007 09:07:16 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/quick-tips/using-sqlite-in-php-5/34/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Here is a well-written step-by-step tutorial on how to use SQLite in PHP 5. The tutorial was written by Ilia Alshanetsky and featured in Zend Developer Zone.</p>
<p><a href="http://devzone.zend.com/node/view/id/760">SQLite Introduction</a></p>
<p>For those who don't know, <a href="http://www.sqlite.org/">SQLite</a> is a lightweight embedded database management system, it is available as the default database engine for PHP5. Due to its embedded nature, SQLite store its database on a single file and is significantly faster than MySQL. Backing up SQLite database is as simple as copying its database file to a backup media.</p>
<p>SQLite is an excellent choice for creating and deploying portable web application without the need to do complex db setups on target machines.</p>
<p>Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/php5" rel="tag">php5</a>, <a href="http://technorati.com/tag/sqlite" rel="tag">sqlite</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/LG8mtI546gVYB4lx7TWjByzkQ6s/0/da"><img src="http://feedads.g.doubleclick.net/~a/LG8mtI546gVYB4lx7TWjByzkQ6s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/LG8mtI546gVYB4lx7TWjByzkQ6s/1/da"><img src="http://feedads.g.doubleclick.net/~a/LG8mtI546gVYB4lx7TWjByzkQ6s/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Here is a well-written step-by-step tutorial on how to use SQLite in PHP 5. The tutorial was written by Ilia Alshanetsky and featured in Zend Developer Zone.
SQLite Introduction
For those who don't know, SQLite is a lightweight embedded database management system, it is available as the default database engine for PHP5. Due to its embedded nature, [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/using-sqlite-in-php-5/34/feed/</wfw:commentRss></item><item><title>Truncate  long text with PHP (excerpt function)</title><link>http://phpcode.mypapit.net/truncate-a-very-long-text-with-php-function/33/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Thu, 03 May 2007 09:36:31 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/library/truncate-a-very-long-text-with-php-function/33/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Truncate is a handy function which can truncate a long text into specific length string and adds elipsis (...) after it.</p>
<p>This is an example of how the function "truncate($text,47)" works :<br />
<strong>Before</strong></p>
<div class="igBar"><span id="lcode-18"><a href="#" onclick="javascript:showPlainTxt('code-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-18">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">This is a very long text that I type as an example to show you the functionality of truncate </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>After</strong></p>
<div class="igBar"><span id="lcode-19"><a href="#" onclick="javascript:showPlainTxt('code-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-19">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">This is a very long text that I type as an exam.... </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here's the PHP code that can let you do just that :</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> truncate <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$str</span>, <span style="color:#0000FF;">$length</span>=<span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#0000FF;">$trailing</span>=<span style="color:#FF0000;">'...'</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">** $str -String to truncate</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">** $length - length to truncate</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">** $trailing - the trailing character, default: &quot;...&quot;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// take off chars for the trailing</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$length</span>-=<a href="http://www.php.net/mb_strlen"><span style="color:#000066;">mb_strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$trailing</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/mb_strlen"><span style="color:#000066;">mb_strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$str</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt; <span style="color:#0000FF;">$length</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#FF9933; font-style:italic;">// string exceeded length, truncate and add trailing dots</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">return</span> <a href="http://www.php.net/mb_substr"><span style="color:#000066;">mb_substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$str</span>,<span style="color:#CC66CC;color:#800000;">0</span>,<span style="color:#0000FF;">$length</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#0000FF;">$trailing</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">else</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#FF9933; font-style:italic;">// string was already short enough, return the string</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$res</span> = <span style="color:#0000FF;">$str</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">return</span> <span style="color:#0000FF;">$res</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p><strong>Truncate as an excerpt function</strong><br />
Truncate can be use to create excerpts from a very long text to serve as a preview or summary on your PHP application.</p>
<p>Tags: <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/truncate" rel="tag">truncate</a>, <a href="http://technorati.com/tag/shorten" rel="tag">shorten</a>, <a href="http://technorati.com/tag/example" rel="tag">example</a>, <a href="http://technorati.com/tag/code" rel="tag">code</a>, <a href="http://technorati.com/tag/phpcode" rel="tag">phpcode</a>, <a href="http://technorati.com/tag/tutorial" rel="tag">tutorial</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/inOVd_IeQMuhVky_zmoT08Surcg/0/da"><img src="http://feedads.g.doubleclick.net/~a/inOVd_IeQMuhVky_zmoT08Surcg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/inOVd_IeQMuhVky_zmoT08Surcg/1/da"><img src="http://feedads.g.doubleclick.net/~a/inOVd_IeQMuhVky_zmoT08Surcg/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Truncate is a handy function which can truncate a long text into specific length string and adds elipsis (...) after it.
This is an example of how the function "truncate($text,47)" works :
Before
PLAIN TEXT
CODE:




This is a very long text that I type as an example to show you the functionality of truncate 






After
PLAIN TEXT
CODE:




This is a very [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/truncate-a-very-long-text-with-php-function/33/feed/</wfw:commentRss></item><item><title>PCRE Cheat Sheet (Perl Compatible Regular Expression)</title><link>http://phpcode.mypapit.net/pcre-cheat-sheet-perl-compatible-regular-expression/32/</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jon Moffet</dc:creator><pubDate>Thu, 03 May 2007 07:26:43 PDT</pubDate><guid isPermaLink="false">http://phpcode.mypapit.net/php-core/pcre-cheat-sheet-perl-compatible-regular-expression/32/</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[<p>Regular Expression (Regex, for short) is a very powerful feature in the PHP programming language. It is useful for manipulating strings using a set of well-defined rules. </p>
<p>However  the often complex syntax rules used in Regex can prove to be a challenge to some. Thankfully, the folks at PHPGure has produced a nice and easy to read PCRE Cheat Sheet which contains commonly use Regex syntax like (\w) (\d) (\s) as a source of reference.</p>
<p>Download <a href="http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf"> PCRE (Perl Compatible Regular Expression) Cheat Sheet</a> (pdf) here</p>
<p>p/s: I've personally have the cheat sheet plastered on the wall of my room to remind me of the common regex shortcut (yes, I'm sucks at regex).</p>
<p>Tags: <a href="http://technorati.com/tag/pcre" rel="tag">pcre</a>, <a href="http://technorati.com/tag/perl" rel="tag">perl</a>, <a href="http://technorati.com/tag/php" rel="tag">php</a>, <a href="http://technorati.com/tag/regex" rel="tag">regex</a>, <a href="http://technorati.com/tag/regular+expression" rel="tag">regular expression</a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/YX3bjRp3sJV2Ypv7MLl00DHrSzg/0/da"><img src="http://feedads.g.doubleclick.net/~a/YX3bjRp3sJV2Ypv7MLl00DHrSzg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YX3bjRp3sJV2Ypv7MLl00DHrSzg/1/da"><img src="http://feedads.g.doubleclick.net/~a/YX3bjRp3sJV2Ypv7MLl00DHrSzg/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded><description>Regular Expression (Regex, for short) is a very powerful feature in the PHP programming language. It is useful for manipulating strings using a set of well-defined rules. 
However  the often complex syntax rules used in Regex can prove to be a challenge to some. Thankfully, the folks at PHPGure has produced a nice and [...]</description><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://phpcode.mypapit.net/pcre-cheat-sheet-perl-compatible-regular-expression/32/feed/</wfw:commentRss></item></channel></rss>
