<?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>David Tavarez's Home at davidtavarez.com &#187; PHP</title>
	<atom:link href="http://www.davidtavarez.com/archives/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidtavarez.com</link>
	<description>Just another weblog...</description>
	<lastBuildDate>Sat, 31 Jul 2010 16:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Face detection using PHP</title>
		<link>http://www.davidtavarez.com/archives/face-detection-using-php/</link>
		<comments>http://www.davidtavarez.com/archives/face-detection-using-php/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 15:33:53 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=489</guid>
		<description><![CDATA[Recently I heard about OpenCV and some applications for AI using this library. This is a interesting topic and very powerful. There is many examples in C, C++ and Python, but I really surprised because I found 2 implementations in PHP. First of all, What Face Detection/Recognition is? Is a computer technology that determines the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I heard about <a href="http://opencv.willowgarage.com/wiki/" onclick="urchinTracker('/outgoing/opencv.willowgarage.com/wiki/?referer=');">OpenCV</a> and some applications for AI using this library. This is a interesting topic and very powerful. There is many examples in C, C++ and Python, but I really surprised because I found 2 implementations in PHP.</p>
<p>First of all, What <strong>Face Detection/Recognition</strong> is?</p>
<p>Is a computer technology that determines the locations and sizes of human faces in arbitrary (digital) images. It detects facial features and ignores anything else, such as buildings, trees and bodies.</p>
<p>How to do this in PHP?</p>
<p><a href="http://www.xarg.org/2008/07/face-detection-with-php/" onclick="urchinTracker('/outgoing/www.xarg.org/2008/07/face-detection-with-php/?referer=');">OpenCV wrapper to detect faces with PHP</a>. The extension offers the two new functions: face_count() and face_detect(). In princible, they differ only by their return value. The first returns only the number of faces found on the given image and the other an associative array of their coordinates. face_count() serves only to save the loops for counting. Examples:<br />
<img src="http://www.xarg.org/image/faces/a1.jpg" alt="OpenCV in PHP example 1" /><br />
<img src="http://www.xarg.org/image/faces/2.jpg" alt="OpenCV in PHP example 2" /></p>
<p><a href="http://www.svay.com/blog/index/post/2009/06/19/Face-detection-in-pure-PHP-(without-OpenCV)" onclick="urchinTracker('/outgoing/www.svay.com/blog/index/post/2009/06/19/Face-detection-in-pure-PHP-_without-OpenCV?referer=');">Face detection in pure PHP (without OpenCV)</a>. This is a PHP Class to face recognition without OpenCV, it use an data file, but not external libraries. We can use it with few code:</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$detector</span> = <span style="color: #000000; font-weight: bold;">new</span> Face_Detector<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'detection.dat'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$detector</span>-&gt;<span style="color: #006600;">face_detect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'maurice_svay_150.jpg'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$detector</span>-&gt;<span style="color: #006600;">toJpeg</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Example:<br />
<img src="http://svay.com/blog/public/images/2009-06-19/detection.jpg" alt="Example FaceDetection" /></p>
<p>Enjoy it!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/face-detection-using-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/face-detection-using-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/face-detection-using-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/face-detection-using-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/face-detection-using-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How many times a value is on an array using php</title>
		<link>http://www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/</link>
		<comments>http://www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 05:07:16 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=462</guid>
		<description><![CDATA[This is a very simple function, but ver useful. Enjoy it! &#160; function getRepetitions&#40;$value, array $values&#41;&#123; $length = count&#40;$values&#41;; if&#40;$length==0&#41; return FALSE; $repetitions = 0; foreach&#40;$values as $v&#41;&#123; if&#40;$v==$value&#41; $repetitions++; &#125; return $repetitions; &#125; print getRepetitions&#40;3,array&#40;3,3,3,5,6,4,3,6,5,4,6,3,2,8,8&#41;&#41;.&#34;\n&#34;; &#160; Share on Facebook]]></description>
			<content:encoded><![CDATA[<p>This is a very simple function, but ver useful. Enjoy it!</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getRepetitions<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$value</span>, <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$values</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$length</span> = <a href="http://www.php.net/count" onclick="urchinTracker('/outgoing/www.php.net/count?referer=');"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$values</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$length</span>==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
	<span style="color: #0000ff;">$repetitions</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$values</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$v</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$v</span>==<span style="color: #0000ff;">$value</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #0000ff;">$repetitions</span>++;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$repetitions</span>;
<span style="color: #66cc66;">&#125;</span>
<a href="http://www.php.net/print" onclick="urchinTracker('/outgoing/www.php.net/print?referer=');"><span style="color: #000066;">print</span></a> getRepetitions<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span>,<a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/how-many-times-a-value-is-on-an-array-using-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculate the &#8220;mode&#8221; of a list of values using PHP</title>
		<link>http://www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/</link>
		<comments>http://www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 04:29:21 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=458</guid>
		<description><![CDATA[In statistics, the mode is the value that occurs the most frequently in a data set or a probability distribution. In some fields, notably education, sample data are often called scores, and the sample mode is known as the modal score. Like the statistical mean and the median, the mode is a way of capturing [...]]]></description>
			<content:encoded><![CDATA[<p>In statistics, the mode is the value that occurs the most frequently in a data set or a probability distribution. In some fields, notably education, sample data are often called scores, and the sample mode is known as the modal score. Like the statistical mean and the median, the mode is a way of capturing important information about a random variable or a population in a single quantity. The mode is in general different from the mean and median, and may be very different for strongly skewed distributions.</p>
<p>Here's the function. Enjoy it!</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getMode<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a> <span style="color: #0000ff;">$valores</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$longitud</span> = <a href="http://www.php.net/count" onclick="urchinTracker('/outgoing/www.php.net/count?referer=');"><span style="color: #000066;">count</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$valores</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$repeticiones</span> = <a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$longitud</span>==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
	<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$valores</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$valor</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$repeticiones</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$valor</span><span style="color: #66cc66;">&#93;</span>=<span style="color: #cc66cc;">0</span>;
		<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>=<span style="color: #cc66cc;">0</span>;<span style="color: #0000ff;">$i</span>&lt;<span style="color: #0000ff;">$longitud</span>;<span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$valores</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #0000ff;">$valor</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #0000ff;">$repeticiones</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$valor</span><span style="color: #66cc66;">&#93;</span>++;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<a href="http://www.php.net/unset" onclick="urchinTracker('/outgoing/www.php.net/unset?referer=');"><span style="color: #000066;">unset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$valores</span>,<span style="color: #0000ff;">$longitud</span>,<span style="color: #0000ff;">$i</span>,<span style="color: #0000ff;">$valor</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/asort" onclick="urchinTracker('/outgoing/www.php.net/asort?referer=');"><span style="color: #000066;">asort</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$repeticiones</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$llaves</span> = <a href="http://www.php.net/array_keys" onclick="urchinTracker('/outgoing/www.php.net/array_keys?referer=');"><span style="color: #000066;">array_keys</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$repeticiones</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <a href="http://www.php.net/array_pop" onclick="urchinTracker('/outgoing/www.php.net/array_pop?referer=');"><span style="color: #000066;">array_pop</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$llaves</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<a href="http://www.php.net/print" onclick="urchinTracker('/outgoing/www.php.net/print?referer=');"><span style="color: #000066;">print</span></a> getMode<span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array" onclick="urchinTracker('/outgoing/www.php.net/array?referer=');"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">5</span>,<span style="color: #cc66cc;">4</span>,<span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">8</span>,<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/calculate-the-mode-of-a-list-of-values-using-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Modifying Tweetme: replace bit.ly by microuri.com</title>
		<link>http://www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/</link>
		<comments>http://www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 07:40:11 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=454</guid>
		<description><![CDATA[This was a quick modification to use use MicroUri, instead bit.ly on Tweetme plugin. We just need to change a function called tweetme_bitly_link(). &#160; function tweetme_bitly_link&#40;$id&#41; &#123; &#160; if &#40;function_exists&#40;'revcanonical_shorten'&#41; &#38;&#38; $link = revcanonical_shorten&#40;$id&#41;&#41; &#123; return $link; &#125; else &#123; $link = get_permalink&#40;$id&#41;; /**Williams Mendez **/ $ob = @simplexml_load_file&#40;'http://api.microuri.com/get.php?url='.$link&#41;; if&#40;is_object&#40;$ob&#41; &#38;&#38; isset&#40;$ob-&#62;Response&#41; &#38;&#38; strlen&#40;$ob-&#62;Response&#41;&#41; return [...]]]></description>
			<content:encoded><![CDATA[<p>This was a quick modification to use use <a href="http://microuri.com" onclick="urchinTracker('/outgoing/microuri.com?referer=');">MicroUri</a>, instead bit.ly on Tweetme plugin. We just need to change a function called <em>tweetme_bitly_link()</em>.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> tweetme_bitly_link<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$id</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/function_exists" onclick="urchinTracker('/outgoing/www.php.net/function_exists?referer=');"><span style="color: #000066;">function_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'revcanonical_shorten'</span><span style="color: #66cc66;">&#41;</span> &amp;&amp;
                                <span style="color: #0000ff;">$link</span> = revcanonical_shorten<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$id</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$link</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$link</span> = get_permalink<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$id</span><span style="color: #66cc66;">&#41;</span>;
               <span style="color: #808080; font-style: italic;">/**Williams Mendez **/</span>
	<span style="color: #0000ff;">$ob</span> = @simplexml_load_file<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://api.microuri.com/get.php?url='</span>.<span style="color: #0000ff;">$link</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_object" onclick="urchinTracker('/outgoing/www.php.net/is_object?referer=');"><span style="color: #000066;">is_object</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ob</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; <a href="http://www.php.net/isset" onclick="urchinTracker('/outgoing/www.php.net/isset?referer=');"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ob</span>-&gt;<span style="color: #006600;">Response</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; <a href="http://www.php.net/strlen" onclick="urchinTracker('/outgoing/www.php.net/strlen?referer=');"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ob</span>-&gt;<span style="color: #006600;">Response</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$ob</span>-&gt;<span style="color: #006600;">Response</span>;
		<span style="color: #b1b100;">return</span> <a href="http://www.php.net/file_get_contents" onclick="urchinTracker('/outgoing/www.php.net/file_get_contents?referer=');"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'http://bit.ly/api?url='</span> . <span style="color: #0000ff;">$link</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p><em>Note: This url shortening and wordpress hack is provided by <a href="http://williamsmendez.com" onclick="urchinTracker('/outgoing/williamsmendez.com?referer=');">Williams Mendez</a>.</em></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/modifying-tweetme-replace-bit-ly-by-microuri-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate an IP Address using PHP and Regular Expressions</title>
		<link>http://www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/</link>
		<comments>http://www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 03:08:06 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=448</guid>
		<description><![CDATA[This php function Validate an IP Address using PHP and Regular Expressions, returns 1 if the IP is valid or 0 if is invalid. The regular expression rather ugly, but still functional and can be very useful. Enjoy it! &#160; function valid_ip&#40;$ip&#41; &#123; return preg_match&#40;&#34;/^([1-9]&#124;[1-9][0-9]&#124;1[0-9][0-9]&#124;2[0-4][0-9]&#124;25[0-5])&#34; . &#34;(\.([0-9]&#124;[1-9][0-9]&#124;1[0-9][0-9]&#124;2[0-4][0-9]&#124;25[0-5])){3}$/&#34;, $ip&#41;; &#125; &#160; Share on Facebook]]></description>
			<content:encoded><![CDATA[<p>This php function Validate an IP Address using PHP and Regular Expressions, returns 1 if the IP is valid or 0 if is invalid. The regular expression rather ugly, but still functional and can be very useful. Enjoy it!</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> valid_ip<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ip</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/preg_match" onclick="urchinTracker('/outgoing/www.php.net/preg_match?referer=');"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])&quot;</span> .
            <span style="color: #ff0000;">&quot;(<span style="color: #000099; font-weight: bold;">\.</span>([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/&quot;</span>, <span style="color: #0000ff;">$ip</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/validate-an-ip-address-using-php-and-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Longer Common SubString Problem&#8221; PHP Implementation</title>
		<link>http://www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/</link>
		<comments>http://www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 16:15:34 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=397</guid>
		<description><![CDATA[The longest common substring problem is to find the longest string (or strings) that is a substring (or are substrings) of two or more strings. The problem of longest common subsequence arises whenever we search for similarities across multiple texts. A particularly important application is in finding a consensus among DNA sequences. The genes for [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>longest common substring problem</strong> is to find the longest string (or strings) that is a substring (or are substrings) of two or more strings.</p>
<p>The problem of longest common subsequence arises whenever we search for similarities across multiple texts. A particularly important application is in finding a consensus among DNA sequences. The genes for building particular proteins evolve with time, but the functional regions must remain consistent in order to work correctly. By finding the longest common subsequence of the same gene in different species, we learn what has been conserved over time.</p>
<p>The longest common substring problem is a special case of edit distance, when substitutions are forbidden and only exact character match, insert, and delete are allowable edit operations. Under these conditions, the edit distance between p and t is n+m-2 |lcs(p,t)|, since we can delete the missing characters from p to the lcs(p,t) and insert the missing characters from $t$ to transform p to t. This is particularly interesting because the longest common subsequence can be faster to compute than edit distance.</p>
<p>For More Information about it, just <a title="Longest common substring problem" href="http://www.google.com/search?rls=ig&amp;hl=en&amp;q=Longest+common+substring+problem&amp;btnG=Google+Search&amp;aq=f&amp;oq=" onclick="urchinTracker('/outgoing/www.google.com/search?rls=ig_amp_hl=en_amp_q=Longest+common+substring+problem_amp_btnG=Google+Search_amp_aq=f_amp_oq=&amp;referer=');">google it!</a>.</p>
<p><strong>The Implementation</strong>.</p>
<pre class="php"><span style="color: #808080; font-style: italic;">/**
 * Implementación de el Algoritmo &quot;Longer Common SubString&quot; en dos (2) Cadenas dadas.
 *
 * @param string $a
 * @param string $b
 * @return integer
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> lcs<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$a</span>, <span style="color: #0000ff;">$b</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>! <a href="http://www.php.net/is_string" onclick="urchinTracker('/outgoing/www.php.net/is_string?referer=');"><span style="color: #000066;">is_string</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$a</span> <span style="color: #66cc66;">&#41;</span> || ! <a href="http://www.php.net/is_string" onclick="urchinTracker('/outgoing/www.php.net/is_string?referer=');"><span style="color: #000066;">is_string</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$b</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #0000ff;">$m</span> = <a href="http://www.php.net/strlen" onclick="urchinTracker('/outgoing/www.php.net/strlen?referer=');"><span style="color: #000066;">strlen</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$a</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$n</span> = <a href="http://www.php.net/strlen" onclick="urchinTracker('/outgoing/www.php.net/strlen?referer=');"><span style="color: #000066;">strlen</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$b</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$i</span> &amp;lt; <span style="color: #0000ff;">$m</span>; <span style="color: #0000ff;">$i</span> ++<span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$j</span> = <span style="color: #cc66cc;">0</span>; <span style="color: #0000ff;">$j</span> &amp;lt; <span style="color: #0000ff;">$n</span>; <span style="color: #0000ff;">$j</span> ++<span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">0</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #cc66cc;">1</span>; <span style="color: #0000ff;">$i</span> &amp;lt;= <span style="color: #0000ff;">$m</span>; <span style="color: #0000ff;">$i</span> ++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$j</span> = <span style="color: #cc66cc;">1</span>; <span style="color: #0000ff;">$j</span> &amp;lt;= <span style="color: #0000ff;">$n</span>; <span style="color: #0000ff;">$j</span> ++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$a</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> == <span style="color: #0000ff;">$b</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> + <span style="color: #cc66cc;">1</span>;
			<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span> &amp;gt;= <span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span>;
				<span style="color: #b1b100;">else</span>
					<span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$j</span> - <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$c</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$m</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$n</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/longer-common-substring-problem-php-implementation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create Daemons in PHP</title>
		<link>http://www.davidtavarez.com/archives/how-to-create-daemons-in-php/</link>
		<comments>http://www.davidtavarez.com/archives/how-to-create-daemons-in-php/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 19:07:05 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=378</guid>
		<description><![CDATA[What is a Daemon? In Unix and other computer multitasking operating systems, a daemon is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What is a Daemon?</strong></p>
<p>In Unix and other computer multitasking operating systems, a daemon is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH connections.</p>
<p>In the Microsoft DOS environment, such programs were written as Terminate and Stay Resident (TSR) software. On Microsoft Windows systems, programs called services perform the functions of daemons. They run as processes, usually do not interact with the monitor, keyboard, and mouse, and may be launched by the operating system at boot time. With Windows NT and later versions, one can configure and manually start and stop Windows services using the Control Panel -&gt; Services applet.</p>
<p><strong>Daemons in PHP</strong></p>
<p>There is a PHP class created by <a title="Kevin van Zonneveld" href="http://kevin.vanzonneveld.net/about/" onclick="urchinTracker('/outgoing/kevin.vanzonneveld.net/about/?referer=');">Kevin van Zonneveld</a> that is very helpfull, you can download from <a title="System Daemon - Download" href="http://pear.php.net/package/System_Daemon/download" onclick="urchinTracker('/outgoing/pear.php.net/package/System_Daemon/download?referer=');">here</a>. I think everyone have to take a look. For more information go here: <a title="Create Daemons in PHP" href="http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/" onclick="urchinTracker('/outgoing/kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/?referer=');">Create Daemons in PHP</a>.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/how-to-create-daemons-in-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/how-to-create-daemons-in-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/how-to-create-daemons-in-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/how-to-create-daemons-in-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/how-to-create-daemons-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP functions in Javascript</title>
		<link>http://www.davidtavarez.com/archives/php-functions-in-javascript/</link>
		<comments>http://www.davidtavarez.com/archives/php-functions-in-javascript/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 18:38:28 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=373</guid>
		<description><![CDATA[I like javascript, but I spend too much time wrting some functions just to use it more than once.  In most cases I uses prototype.js to create a shorter code but still being long. Recently I was porting some basic php functions to javascript like  isset(), array_keys(), in_array(), explode() and many more. I was very [...]]]></description>
			<content:encoded><![CDATA[<p>I like javascript, but I spend too much time wrting some functions just to use it more than once.  In most cases I uses prototype.js to create a shorter code but still being long. Recently I was porting some basic php functions to javascript like  isset(), array_keys(), in_array(), explode() and many more. I was very frustrated, because I had to write a mini-framework just to create a simple application. Within a few hours had hundreds of lines of code.</p>
<p>Then on Internet I found this: PHP.js, an open source project in which they try to port PHP functions to JavaScript. By including the PHP.JS library in your own projects, you can use your favorite PHP functions on the client-side. This convenience may speed up development for PHP developers who are increasingly confronted with client-side technology.</p>
<p><strong>The History of PHP.JS</strong></p>
<p>A developer called <a title="Kevin van Zonneveld" href="http://kevin.vanzonneveld.net/about/" onclick="urchinTracker('/outgoing/kevin.vanzonneveld.net/about/?referer=');">Kevin van Zonneveld</a> was once working on a project with a lot of client(JS) / server(PHP) interaction, and he found himself coding PHP functions (like base64_decode &amp; urldecode) in JavaScript to smoothen communication between the two languages. He stored the stored the functions in a file called php.js which was included in the project. Kevin decided to share the little library online, which triggered the enthusiasm of a lot of PHP developers longing for PHP functionality in JavaScript. The project was open sourced in 2008, and many people contributed their own functions in the comments sections of Kevin's blog. It was decided that the library deserved a bigger home, and a face of its own, and so the PHP.JS core team developed the phpjs.org website.</p>
<p><strong>List of functions</strong></p>
<p>To see the list of functions click here <a title="PHP.js: Functions Overview" href="http://phpjs.org/functions/index" onclick="urchinTracker('/outgoing/phpjs.org/functions/index?referer=');">PHP.JS: Functions Overview</a>.</p>
<p>More Information:  <a title="PHP.js: Pages" href="http://phpjs.org/" onclick="urchinTracker('/outgoing/phpjs.org/?referer=');">http://phpjs.org/</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/php-functions-in-javascript/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/php-functions-in-javascript/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/php-functions-in-javascript/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/php-functions-in-javascript/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/php-functions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting visitors language using PHP</title>
		<link>http://www.davidtavarez.com/archives/detecting-visitors-language-using-php/</link>
		<comments>http://www.davidtavarez.com/archives/detecting-visitors-language-using-php/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 19:49:57 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=346</guid>
		<description><![CDATA[Sometimes we have to create web sites or web applications that must be translated into different languages according to user settings. If we are using PHP this goal is very easy. PHP have predefined variables like $_POST, $_GET, $_SESSION and more. One of this variables is $_SERVER that is an array containing information such as [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we have to create web sites or web applications that must be translated into different languages according to user settings. If we are using PHP this goal is very easy.</p>
<p><a title="PHP" href="http://www.php.net" onclick="urchinTracker('/outgoing/www.php.net?referer=');">PHP</a> have predefined variables like $_POST, $_GET, $_SESSION and more. One of this variables is <a title="PHP: $_SERVER - Manual" href="http://www.php.net/manual/en/reserved.variables.server.php" onclick="urchinTracker('/outgoing/www.php.net/manual/en/reserved.variables.server.php?referer=');">$_SERVER</a> that is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.</p>
<p>The index that we going to use is: "HTTP_ACCEPT_LANGUAGE" because this index shows the contents of the <em>Accept-Language</em>: header from the current request, if there is one. Example: 'es-ar,es;q=0.8,en-us;q=0.5,en;q=0.3'</p>
<p><strong>The Code</strong><br />
Now we can create the code.</p>
<p><span id="more-346"></span><br />
As we can see, the first 2 letters says the main language and the next two specifies the country. Another options that we have is to take the "q" values, those values shows the percentage probabilityfor others language including the main one.</p>
<p>In just 1 line we could determine the visitor language:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/substr" onclick="urchinTracker('/outgoing/www.php.net/substr?referer=');"><span style="color: #000066;">substr</span></a> <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">$_SERVER</span> <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;HTTP_ACCEPT_LANGUAGE&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>And that's it!!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/detecting-visitors-language-using-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/detecting-visitors-language-using-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/detecting-visitors-language-using-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/detecting-visitors-language-using-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/detecting-visitors-language-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect Mobile Browsers using PHP</title>
		<link>http://www.davidtavarez.com/archives/detect-mobile-browsers-using-php/</link>
		<comments>http://www.davidtavarez.com/archives/detect-mobile-browsers-using-php/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 21:48:27 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.davidtavarez.com/?p=274</guid>
		<description><![CDATA[Detecting web browsers with php is very easy. To detect the browser itselft we can use the predefined variable: $_SERVER. This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. To get the browser we just need to check the $_SERVER['HTTP_USER_AGENT'] [...]]]></description>
			<content:encoded><![CDATA[<p>Detecting web browsers with php is very easy. To detect the browser itselft we can use the predefined variable: $_SERVER. This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. To get the browser we just need to check the $_SERVER['HTTP_USER_AGENT'] variable, this variable contents of the <em>User-Agent</em>: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page.</p>
<p><strong>The get_browser() function</strong></p>
<p>The <strong>get_browser()</strong> function tells what the user's browser is capable of. This function was is supported by PHP 4 and PHP 5. To use this function we need to do 2 things: First, we need to configure the <em>browscap</em> directive on the <em>php.ini</em> file. Second, we need to have a browscap.ini file, that is the file that contain all the up-to-date information about web browsers. The get_browser() function just parse this file,match the user-agent and return an object or an array with the specific configuration of the browser.</p>
<p>To get the browscap file, just go there: <a title="Downloads :: Browser Capabilities Project" href="http://browsers.garykeith.com/downloads.asp" onclick="urchinTracker('/outgoing/browsers.garykeith.com/downloads.asp?referer=');">Downloads :: Browser Capabilities Project</a>.</p>
<p>When you got the file, open your php.ini and find the <em>browscap</em> line, write the path for the file and restart the web server.</p>
<p>Example:</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_USER_AGENT'</span><span style="color: #66cc66;">&#93;</span> . <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #0000ff;">$browser</span> = <a href="http://www.php.net/get_browser" onclick="urchinTracker('/outgoing/www.php.net/get_browser?referer=');"><span style="color: #000066;">get_browser</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/print_r" onclick="urchinTracker('/outgoing/www.php.net/print_r?referer=');"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$browser</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>Then there is an element called <em>ismobiledevice</em> that contain an empty value if is not a mobile device or 1, if the device is mobile.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff;">$browser</span> = <a href="http://www.php.net/get_browser" onclick="urchinTracker('/outgoing/www.php.net/get_browser?referer=');"><span style="color: #000066;">get_browser</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$browser</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'ismobiledevice'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p><strong>Alternative (and better) option</strong></p>
<p>If you are using a shared hosting, maybe you can't edit the php.ini and the ini_set() function doesn't work either. So this is an alternative option.</p>
<p>Click here to download the function: <a href="http://www.davidtavarez.com/wp-content/2008/12/detect_mobile_browser.zip">detect_mobile_browser</a></p>
<p><strong>Using the functions</strong></p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">include</span> <span style="color: #ff0000;">'detect_mobile_browser.php'</span>;
<span style="color: #0000ff;">$browser_info</span> = php_get_browser<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'php_browscap.ini'</span>,<span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'HTTP_USER_AGENT'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>ismobiledevice<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$browser_info</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;strong&gt;Mobile device detected&lt;/strong&gt;.Your browser is: &lt;strong&gt;{$browser_info['parent']}&lt;/strong&gt;.&quot;</span>;
<span style="color: #b1b100;">else</span>
<a href="http://www.php.net/echo" onclick="urchinTracker('/outgoing/www.php.net/echo?referer=');"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;No mobile device detected.&quot;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p><em>Note: You can view an example here: <a href="http://demo.dwstudioinc.net/mobileupload/detectar.php" onclick="urchinTracker('/outgoing/demo.dwstudioinc.net/mobileupload/detectar.php?referer=');">http://demo.dwstudioinc.net/mobileupload/detectar.php</a>. I did some test using a Sony Ericsson K550 and G1 (using Android) and works perfect!.</em></p>
<p><strong><em>And that's it!</em></strong></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/detect-mobile-browsers-using-php/" target="_blank" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/detect-mobile-browsers-using-php/&amp;referer=');"><img src="http://www.davidtavarez.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://www.davidtavarez.com/archives/detect-mobile-browsers-using-php/" target="_blank" title="Share on Facebook" onclick="urchinTracker('/outgoing/www.facebook.com/share.php?u=http_//www.davidtavarez.com/archives/detect-mobile-browsers-using-php/&amp;referer=');">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.davidtavarez.com/archives/detect-mobile-browsers-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
