<?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>Joemarie Aliling Tech Blog &#187; PHP Programming</title>
	<atom:link href="http://joemarie-aliling.com/category/php-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://joemarie-aliling.com</link>
	<description>Joemarie Aliling&#039;s Programming and IT blog</description>
	<lastBuildDate>Wed, 30 Dec 2009 00:31:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>phpize not found command</title>
		<link>http://joemarie-aliling.com/245/php-programming/phpize-not-found-command/</link>
		<comments>http://joemarie-aliling.com/245/php-programming/phpize-not-found-command/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 07:05:00 +0000</pubDate>
		<dc:creator>Joemarie Aliling</dc:creator>
				<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://joemarie-aliling.com/?p=245</guid>
		<description><![CDATA[Recently, I was installing memcached on a CentOS server and found out that I could not use the command phpize, for a quick solution, here&#8217;s how to do it,
yum install php-devel
Yum is simply the best.  
]]></description>
			<content:encoded><![CDATA[<p>Recently, I was installing memcached on a CentOS server and found out that I could not use the command phpize, for a quick solution, here&#8217;s how to do it,</p>
<p><span><span style="margin-left: 0px ! important;"><code>yum </code><code>install</code> <code>php-devel</code></span></span><br />
Yum is simply the best. <img src='http://joemarie-aliling.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' title="phpize not found command" /> </p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/button" title="phpize not found command" url="http://joemarie-aliling.com/245/php-programming/phpize-not-found-command/"></script><img src="http://joemarie-aliling.com/wp-content/plugins/pixelstats/trackingpixel.php?post_id=245&amp;ts=1268255515" style="display:none;" alt="pixelstats trackingpixel" title="phpize not found command" />]]></content:encoded>
			<wfw:commentRss>http://joemarie-aliling.com/245/php-programming/phpize-not-found-command/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Memcache Not Found problem</title>
		<link>http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/</link>
		<comments>http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 16:14:44 +0000</pubDate>
		<dc:creator>Joemarie Aliling</dc:creator>
				<category><![CDATA[PHP Programming]]></category>

		<guid isPermaLink="false">http://joemarie-aliling.com/?p=223</guid>
		<description><![CDATA[Recently, I was installing memcache libraries and the memcache extension for PHP on one of our Linux boxes. Unfortunately when I tried to run a sample code just to test if everything was successful with the installation, I got an error instead which say Memcache not found. I digged for a couple of days looking [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was installing memcache libraries and the memcache extension for PHP on one of our Linux boxes. Unfortunately when I tried to run a sample code just to test if everything was successful with the installation, I got an error instead which say Memcache not found. I digged for a couple of days looking for solutions to my problem and Googling it didn&#8217;t even help me at all.</p>
<p>Without losing my patience, I tried reading the error logs of httpd(usually in /var/log/httpd/error_log) and somewhere it showed this message,</p>
<p>PHP Warning:  PHP Startup: Unable to load dynamic library &#8216;./memcache.so&#8217; &#8211; ./memcache.so: cannot open shared object file: No such file or directory in Unknown on line 0</p>
<p>After that, I tried to check the php.ini (usually in /usr/local/lib/php.ini) and made sure that the extension=memcache.so was there, and on the extension_dir property, it looked like this,</p>
<p>extension_dir=&#8221;./&#8221;</p>
<p>seeing that, I tried a lucky guess and I changed it to a full path instead,</p>
<p>extension_dir = &#8220;/usr/local/lib/&#8221;</p>
<p>Next, I simply restarted httpd with,</p>
<p>service httpd restart</p>
<p>Then I again checked the httpd error_log and I noticed that the error is gone! With that information, I immediately tried the test PHP code again and Voila! My memcache extension is running perfectly!</p>
<p>Hope this helps.</p>
<p>JM Aliling</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/button" title="PHP: Memcache Not Found problem" url="http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/"></script><img src="http://joemarie-aliling.com/wp-content/plugins/pixelstats/trackingpixel.php?post_id=223&amp;ts=1268255515" style="display:none;" alt="pixelstats trackingpixel" title="PHP: Memcache Not Found problem" />]]></content:encoded>
			<wfw:commentRss>http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scraping links from webpage using PHP cURL</title>
		<link>http://joemarie-aliling.com/19/php-programming/scraping-links-from-webpage-using-php-curl/</link>
		<comments>http://joemarie-aliling.com/19/php-programming/scraping-links-from-webpage-using-php-curl/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 13:28:37 +0000</pubDate>
		<dc:creator>Joemarie Aliling</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[domdocument]]></category>
		<category><![CDATA[domxpath]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php curl]]></category>
		<category><![CDATA[scraping]]></category>
		<category><![CDATA[screen scraping]]></category>

		<guid isPermaLink="false">http://joemarie-aliling.com/?p=19</guid>
		<description><![CDATA[Here&#8217;s a code to scrape for links/url of a webpage using PHP cURL, PHP DOMDocument and PHP DOMXPath.
&#60;?php
$target = &#8220;http://joemarie-aliling.com/category/php-programming/&#8221;;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, &#8220;Firefox (WindowsXP) – Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6)  Gecko/20070725 Firefox/2.0.0.6&#8243;);           //pretend that we are a browser..
$page = curl_exec($ch);
$dom = new DOMDocument();
@$dom-&#62;loadHTML($page);       [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a code to scrape for links/url of a webpage using PHP cURL, PHP DOMDocument and PHP DOMXPath.</p>
<p>&lt;?php</p>
<p>$target = &#8220;http://joemarie-aliling.com/category/php-programming/&#8221;;<br />
$ch = curl_init();<br />
curl_setopt($ch, CURLOPT_URL, $target);<br />
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);<br />
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);<br />
curl_setopt($ch, CURLOPT_USERAGENT, &#8220;Firefox (WindowsXP) – Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6)  Gecko/20070725 Firefox/2.0.0.6&#8243;);           //pretend that we are a browser..<br />
$page = curl_exec($ch);<br />
$dom = new DOMDocument();<br />
@$dom-&gt;loadHTML($page);       //@ suppresses any errors..<br />
$xpath = new DOMXPath($dom);<br />
$hrefs = $xpath-&gt;evaluate(&#8220;/html/body//a&#8221;);        // evaluate everything inside the html and body tags and extract the anchor tag. Read <a title="PHP DOMXPath" href="http://www.php.net/manual/en/domxpath.evaluate.php" target="_self">this</a><br />
for ($i = 0; $i &lt; $hrefs-&gt;length; $i++) {<br />
$href = $hrefs-&gt;item($i);<br />
$url = $href-&gt;getAttribute(&#8216;href&#8217;);<br />
if($url[0] == &#8220;/&#8221; || $url[0] == &#8220;#&#8221;) $url = $target . $url;  // this is to correct relative URLs and page anchors. try to remove this line and        see the effect.<br />
echo $url . &#8220;&lt;br&gt;&#8221;;<br />
}</p>
<p>?&gt;</p>
<p>There you have it! Hope this helps with your screen scraping projects.</p>
<p>-JM</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/button" title="Scraping links from webpage using PHP cURL" url="http://joemarie-aliling.com/19/php-programming/scraping-links-from-webpage-using-php-curl/"></script><img src="http://joemarie-aliling.com/wp-content/plugins/pixelstats/trackingpixel.php?post_id=19&amp;ts=1268255515" style="display:none;" alt="pixelstats trackingpixel" title="Scraping links from webpage using PHP cURL" />]]></content:encoded>
			<wfw:commentRss>http://joemarie-aliling.com/19/php-programming/scraping-links-from-webpage-using-php-curl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Code for extracting base domain from a url</title>
		<link>http://joemarie-aliling.com/6/php-programming/php-code-for-extracting-base-domain-from-a-url/</link>
		<comments>http://joemarie-aliling.com/6/php-programming/php-code-for-extracting-base-domain-from-a-url/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 07:39:02 +0000</pubDate>
		<dc:creator>Joemarie Aliling</dc:creator>
				<category><![CDATA[PHP Programming]]></category>
		<category><![CDATA[base domain]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php code]]></category>
		<category><![CDATA[php snippet]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://joemarie-aliling.com/?p=6</guid>
		<description><![CDATA[Hi everyone,
Let me share this wonderful PHP snippet to you. Its function is to take the base domain of a given url. For example,
say,
$url =  http://www.joemarie-aliling.com/php-programming-tutorial.php
the return value is a string =   joemarie-aliling.com
Also this works even if the URL has a subdomain, like http://subdomain.joemarie-aliling.com/php-coding-tips.php
I&#8217;ve tested this on PHP 5.2.5, but I believe, it would [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>Let me share this wonderful PHP snippet to you. Its function is to take the base domain of a given url. For example,</p>
<p>say,</p>
<p>$url =  http://www.joemarie-aliling.com/php-programming-tutorial.php</p>
<p>the return value is a string =   joemarie-aliling.com</p>
<p>Also this works even if the URL has a subdomain, like http://subdomain.joemarie-aliling.com/php-coding-tips.php</p>
<p>I&#8217;ve tested this on PHP 5.2.5, but I believe, it would work with older versions of PHP.</p>
<p>This is a GNU Licensed, so you may use it freely.<br />
function get_base_domain($url){<br />
$debug = 0;<br />
$base_domain = &#8221;;</p>
<p>// generic tlds (source: http://en.wikipedia.org/wiki/Generic_top-level_domain)<br />
$G_TLD = array(<br />
&#8216;biz&#8217;,'com&#8217;,'edu&#8217;,'gov&#8217;,'info&#8217;,'int&#8217;,'mil&#8217;,'name&#8217;,'net&#8217;,'org&#8217;,<br />
&#8216;aero&#8217;,'asia&#8217;,'cat&#8217;,'coop&#8217;,'jobs&#8217;,'mobi&#8217;,'museum&#8217;,'pro&#8217;,'tel&#8217;,'travel&#8217;,<br />
&#8216;arpa&#8217;,'root&#8217;,<br />
&#8216;berlin&#8217;,'bzh&#8217;,'cym&#8217;,'gal&#8217;,'geo&#8217;,'kid&#8217;,'kids&#8217;,'lat&#8217;,'mail&#8217;,'nyc&#8217;,'post&#8217;,&#8217;sco&#8217;,'web&#8217;,'xxx&#8217;,<br />
&#8216;nato&#8217;,<br />
&#8216;example&#8217;,'invalid&#8217;,'localhost&#8217;,'test&#8217;,<br />
&#8216;bitnet&#8217;,'csnet&#8217;,'ip&#8217;,'local&#8217;,'onion&#8217;,'uucp&#8217;,<br />
&#8216;co&#8217; // note: not technically, but used in things like co.uk<br />
);</p>
<p>// country tlds (source: http://en.wikipedia.org/wiki/Country_code_top-level_domain)<br />
$C_TLD = array(<br />
// active<br />
&#8216;ac&#8217;,'ad&#8217;,'ae&#8217;,'af&#8217;,'ag&#8217;,'ai&#8217;,'al&#8217;,'am&#8217;,'an&#8217;,'ao&#8217;,'aq&#8217;,'ar&#8217;,'as&#8217;,'at&#8217;,'au&#8217;,'aw&#8217;,'ax&#8217;,'az&#8217;,<br />
&#8216;ba&#8217;,'bb&#8217;,'bd&#8217;,'be&#8217;,'bf&#8217;,'bg&#8217;,'bh&#8217;,'bi&#8217;,'bj&#8217;,'bm&#8217;,'bn&#8217;,'bo&#8217;,'br&#8217;,'bs&#8217;,'bt&#8217;,'bw&#8217;,'by&#8217;,'bz&#8217;,<br />
&#8216;ca&#8217;,'cc&#8217;,'cd&#8217;,'cf&#8217;,'cg&#8217;,'ch&#8217;,'ci&#8217;,'ck&#8217;,'cl&#8217;,'cm&#8217;,'cn&#8217;,'co&#8217;,'cr&#8217;,'cu&#8217;,'cv&#8217;,'cx&#8217;,'cy&#8217;,'cz&#8217;,<br />
&#8216;de&#8217;,'dj&#8217;,'dk&#8217;,'dm&#8217;,'do&#8217;,'dz&#8217;,'ec&#8217;,'ee&#8217;,'eg&#8217;,'er&#8217;,'es&#8217;,'et&#8217;,'eu&#8217;,'fi&#8217;,'fj&#8217;,'fk&#8217;,'fm&#8217;,'fo&#8217;,<br />
&#8216;fr&#8217;,'ga&#8217;,'gd&#8217;,'ge&#8217;,'gf&#8217;,'gg&#8217;,'gh&#8217;,'gi&#8217;,'gl&#8217;,'gm&#8217;,'gn&#8217;,'gp&#8217;,'gq&#8217;,'gr&#8217;,'gs&#8217;,'gt&#8217;,'gu&#8217;,'gw&#8217;,<br />
&#8216;gy&#8217;,'hk&#8217;,'hm&#8217;,'hn&#8217;,'hr&#8217;,'ht&#8217;,'hu&#8217;,'id&#8217;,'ie&#8217;,'il&#8217;,'im&#8217;,'in&#8217;,'io&#8217;,'iq&#8217;,'ir&#8217;,'is&#8217;,'it&#8217;,'je&#8217;,<br />
&#8216;jm&#8217;,'jo&#8217;,'jp&#8217;,'ke&#8217;,'kg&#8217;,'kh&#8217;,'ki&#8217;,'km&#8217;,'kn&#8217;,'kr&#8217;,'kw&#8217;,'ky&#8217;,'kz&#8217;,'la&#8217;,'lb&#8217;,'lc&#8217;,'li&#8217;,'lk&#8217;,<br />
&#8216;lr&#8217;,'ls&#8217;,'lt&#8217;,'lu&#8217;,'lv&#8217;,'ly&#8217;,'ma&#8217;,'mc&#8217;,'md&#8217;,'mg&#8217;,'mh&#8217;,'mk&#8217;,'ml&#8217;,'mm&#8217;,'mn&#8217;,'mo&#8217;,'mp&#8217;,'mq&#8217;,<br />
&#8216;mr&#8217;,'ms&#8217;,'mt&#8217;,'mu&#8217;,'mv&#8217;,'mw&#8217;,'mx&#8217;,'my&#8217;,'mz&#8217;,'na&#8217;,'nc&#8217;,'ne&#8217;,'nf&#8217;,'ng&#8217;,'ni&#8217;,'nl&#8217;,'no&#8217;,'np&#8217;,<br />
&#8216;nr&#8217;,'nu&#8217;,'nz&#8217;,'om&#8217;,'pa&#8217;,'pe&#8217;,'pf&#8217;,'pg&#8217;,'ph&#8217;,'pk&#8217;,'pl&#8217;,'pn&#8217;,'pr&#8217;,'ps&#8217;,'pt&#8217;,'pw&#8217;,'py&#8217;,'qa&#8217;,<br />
&#8216;re&#8217;,'ro&#8217;,'ru&#8217;,'rw&#8217;,&#8217;sa&#8217;,&#8217;sb&#8217;,&#8217;sc&#8217;,&#8217;sd&#8217;,&#8217;se&#8217;,&#8217;sg&#8217;,&#8217;sh&#8217;,&#8217;si&#8217;,&#8217;sk&#8217;,&#8217;sl&#8217;,&#8217;sm&#8217;,&#8217;sn&#8217;,&#8217;sr&#8217;,&#8217;st&#8217;,<br />
&#8217;sv&#8217;,&#8217;sy&#8217;,&#8217;sz&#8217;,'tc&#8217;,'td&#8217;,'tf&#8217;,'tg&#8217;,'th&#8217;,'tj&#8217;,'tk&#8217;,'tl&#8217;,'tm&#8217;,'tn&#8217;,'to&#8217;,'tr&#8217;,'tt&#8217;,'tv&#8217;,'tw&#8217;,<br />
&#8216;tz&#8217;,'ua&#8217;,'ug&#8217;,'uk&#8217;,'us&#8217;,'uy&#8217;,'uz&#8217;,'va&#8217;,'vc&#8217;,'ve&#8217;,'vg&#8217;,'vi&#8217;,'vn&#8217;,'vu&#8217;,'wf&#8217;,'ws&#8217;,'ye&#8217;,'yu&#8217;,<br />
&#8216;za&#8217;,'zm&#8217;,'zw&#8217;,<br />
// inactive<br />
&#8216;eh&#8217;,'kp&#8217;,'me&#8217;,'rs&#8217;,'um&#8217;,'bv&#8217;,'gb&#8217;,'pm&#8217;,&#8217;sj&#8217;,&#8217;so&#8217;,'yt&#8217;,&#8217;su&#8217;,'tp&#8217;,'bu&#8217;,'cs&#8217;,'dd&#8217;,'zr&#8217;<br />
);</p>
<p>// get domain<br />
if ( !$full_domain = get_url_domain($url) )<br />
{<br />
return $base_domain;<br />
}</p>
<p>// now the fun</p>
<p>// break up domain, reverse<br />
$DOMAIN = explode(&#8216;.&#8217;, $full_domain);<br />
if ( $debug ) print_r($DOMAIN);<br />
$DOMAIN = array_reverse($DOMAIN);<br />
if ( $debug ) print_r($DOMAIN);</p>
<p>// first check for ip address<br />
if ( count($DOMAIN) == 4 &amp;&amp; is_numeric($DOMAIN[0]) &amp;&amp; is_numeric($DOMAIN[3]) )<br />
{<br />
return $full_domain;<br />
}</p>
<p>// if only 2 domain parts, that must be our domain<br />
if ( count($DOMAIN) &lt;= 2 ) return $full_domain;</p>
<p>if ( in_array($DOMAIN[0], $C_TLD) &amp;&amp; in_array($DOMAIN[1], $G_TLD) &amp;&amp; $DOMAIN[2] != &#8216;www&#8217; )<br />
{<br />
$full_domain = $DOMAIN[2] . &#8216;.&#8217; . $DOMAIN[1] . &#8216;.&#8217; . $DOMAIN[0];<br />
}<br />
else<br />
{<br />
$full_domain = $DOMAIN[1] . &#8216;.&#8217; . $DOMAIN[0];;<br />
}</p>
<p>// did we succeed?<br />
return $full_domain;<br />
}</p>
<p>// get domain from url</p>
<p>function get_url_domain($url)<br />
{<br />
$domain = &#8221;;</p>
<p>$_URL = parse_url($url);</p>
<p>// sanity check<br />
if ( empty($_URL) || empty($_URL['host']) )<br />
{<br />
$domain = &#8221;;<br />
}<br />
else<br />
{<br />
$domain = $_URL['host'];<br />
}</p>
<p>return $domain;<br />
}</p>
<p>Sorry for not indenting this and it looks ugly. But I guarantee you it works!</p>
<p>-Joemarie</p>
<script type="text/javascript" class="owbutton" src="http://onlywire.com/button" title="PHP Code for extracting base domain from a url" url="http://joemarie-aliling.com/6/php-programming/php-code-for-extracting-base-domain-from-a-url/"></script><img src="http://joemarie-aliling.com/wp-content/plugins/pixelstats/trackingpixel.php?post_id=6&amp;ts=1268255515" style="display:none;" alt="pixelstats trackingpixel" title="PHP Code for extracting base domain from a url" />]]></content:encoded>
			<wfw:commentRss>http://joemarie-aliling.com/6/php-programming/php-code-for-extracting-base-domain-from-a-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
