<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: PHP Alexa Rank Fetcher&#160;Class</title> <atom:link href="http://davidwalsh.name/php-alexa-rank-fetcher-xml/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Wed, 23 May 2012 19:56:08 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Ashok sharma</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-28480</link> <dc:creator>Ashok sharma</dc:creator> <pubDate>Sat, 07 Jan 2012 19:50:30 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-28480</guid> <description>Great post.
Exactly what I was looking for my website</description> <content:encoded><![CDATA[<p>Great post.<br
/> Exactly what I was looking for my website</p> ]]></content:encoded> </item> <item><title>By: Roman</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-26253</link> <dc:creator>Roman</dc:creator> <pubDate>Wed, 27 Jul 2011 07:41:06 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-26253</guid> <description>Sorry, i didnt added code tag... lawl..&lt;code&gt;
function AlexaRank( $url )
{
preg_match( &#039;##si&#039;, file_get_contents(&#039;http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=&#039; . $url), $p );
return ( $p[2] ) ? number_format( intval($p[2]) ):0;
}
&lt;/code&gt;Here
&lt;code&gt;
http://www.igloro.info/en/pagerank.html
&lt;/code&gt;</description> <content:encoded><![CDATA[<p>Sorry, i didnt added code tag&#8230; lawl..</p><p><code><br
/> function AlexaRank( $url )<br
/> {<br
/> preg_match( '##si', file_get_contents('http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=' . $url), $p );<br
/> return ( $p[2] ) ? number_format( intval($p[2]) ):0;<br
/> }<br
/> </code></p><p>Here<br
/> <code><br
/> <a
href="http://www.igloro.info/en/pagerank.html" rel="nofollow">http://www.igloro.info/en/pagerank.html</a><br
/> </code></p> ]]></content:encoded> </item> <item><title>By: Graham McLellan</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-22533</link> <dc:creator>Graham McLellan</dc:creator> <pubDate>Wed, 02 Feb 2011 08:16:14 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-22533</guid> <description>Here&#039;s my class in action: http://www.swordfoxdesign.co.nz/resources/alexa-rank-tool/&lt;code&gt;
class alexa
{
/* initial vars */
var $alexa_address=&#039;http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=&#039;;
function wp_xml2array($__url){
$xml_values = array();
$contents = file_get_contents($__url);
$parser = xml_parser_create(&#039;&#039;);
if(!$parser)
return false;
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, &#039;UTF-8&#039;);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($contents), $xml_values);
xml_parser_free($parser);
if (!$xml_values)
return array();
$xml_array = array();
$last_tag_ar =&amp; $xml_array;
$parents = array();
$last_counter_in_tag = array(1=&gt;0);
foreach ($xml_values as $data)
{
switch($data[&#039;type&#039;])
{
case &#039;open&#039;:
$last_counter_in_tag[$data[&#039;level&#039;]+1] = 0;
$new_tag = array(&#039;name&#039; =&gt; $data[&#039;tag&#039;]);
if(isset($data[&#039;attributes&#039;]))
$new_tag[&#039;attributes&#039;] = $data[&#039;attributes&#039;];
if(isset($data[&#039;value&#039;]) &amp;&amp; trim($data[&#039;value&#039;]))
$new_tag[&#039;value&#039;] = trim($data[&#039;value&#039;]);
$last_tag_ar[$last_counter_in_tag[$data[&#039;level&#039;]]] = $new_tag;
$parents[$data[&#039;level&#039;]] =&amp; $last_tag_ar;
$last_tag_ar =&amp; $last_tag_ar[$last_counter_in_tag[$data[&#039;level&#039;]]++];
break;
case &#039;complete&#039;:
$new_tag = array(&#039;name&#039; =&gt; $data[&#039;tag&#039;]);
if(isset($data[&#039;attributes&#039;]))
$new_tag[&#039;attributes&#039;] = $data[&#039;attributes&#039;];
if(isset($data[&#039;value&#039;]) &amp;&amp; trim($data[&#039;value&#039;]))
$new_tag[&#039;value&#039;] = trim($data[&#039;value&#039;]);
$last_count = count($last_tag_ar)-1;
$last_tag_ar[$last_counter_in_tag[$data[&#039;level&#039;]]++] = $new_tag;
break;
case &#039;close&#039;:
$last_tag_ar =&amp; $parents[$data[&#039;level&#039;]];
break;
default:
break;
};
}
return $xml_array;
}
//
// use this to get node of tree by path with &#039;/&#039; terminator
//
function wp_get_value_by_path($__xml_tree, $__tag_path)
{
$tmp_arr =&amp; $__xml_tree;
$tag_path = explode(&#039;/&#039;, $__tag_path);
foreach($tag_path as $tag_name)
{
$res = false;
foreach($tmp_arr as $key =&gt; $node)
{
if(is_int($key) &amp;&amp; $node[&#039;name&#039;] == $tag_name)
{
$tmp_arr = $node;
$res = true;
break;
}
}
if(!$res)
return false;
}
return $tmp_arr;
}
function getRank($url)
{
$arr = $this-&gt;wp_xml2array($this-&gt;alexa_address.$url);
$arr2= $this-&gt;wp_get_value_by_path($arr, &#039;ALEXA&#039;);
$arr3=($arr2[2][0][&#039;attributes&#039;]);
$rank=$arr3[&#039;TEXT&#039;];
$rank=($rank==&#039;&#039; ? &#039;Not ranked yet&#039; : $rank);
return $rank;
}
}
&lt;/code&gt;Call using this:&lt;code&gt;
$alexa = new Alexa();
$rank = $alexa-&gt;getRank(str_replace(&#039;http://&#039;, &#039;&#039;, $url));
&lt;/code&gt;</description> <content:encoded><![CDATA[<p>Here&#8217;s my class in action: <a
href="http://www.swordfoxdesign.co.nz/resources/alexa-rank-tool/" rel="nofollow">http://www.swordfoxdesign.co.nz/resources/alexa-rank-tool/</a></p><p><code><br
/> class alexa<br
/> {<br
/> /* initial vars */<br
/> var $alexa_address='http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=';</p><p> function wp_xml2array($__url){<br
/> $xml_values = array();<br
/> $contents = file_get_contents($__url);<br
/> $parser = xml_parser_create('');<br
/> if(!$parser)<br
/> return false;</p><p> xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');<br
/> xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);<br
/> xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);<br
/> xml_parse_into_struct($parser, trim($contents), $xml_values);<br
/> xml_parser_free($parser);<br
/> if (!$xml_values)<br
/> return array();</p><p> $xml_array = array();<br
/> $last_tag_ar =&amp; $xml_array;<br
/> $parents = array();<br
/> $last_counter_in_tag = array(1=&gt;0);<br
/> foreach ($xml_values as $data)<br
/> {<br
/> switch($data['type'])<br
/> {<br
/> case 'open':<br
/> $last_counter_in_tag[$data['level']+1] = 0;<br
/> $new_tag = array('name' =&gt; $data['tag']);<br
/> if(isset($data['attributes']))<br
/> $new_tag['attributes'] = $data['attributes'];<br
/> if(isset($data['value']) &amp;&amp; trim($data['value']))<br
/> $new_tag['value'] = trim($data['value']);<br
/> $last_tag_ar[$last_counter_in_tag[$data['level']]] = $new_tag;<br
/> $parents[$data['level']] =&amp; $last_tag_ar;<br
/> $last_tag_ar =&amp; $last_tag_ar[$last_counter_in_tag[$data['level']]++];<br
/> break;<br
/> case 'complete':<br
/> $new_tag = array('name' =&gt; $data['tag']);<br
/> if(isset($data['attributes']))<br
/> $new_tag['attributes'] = $data['attributes'];<br
/> if(isset($data['value']) &amp;&amp; trim($data['value']))<br
/> $new_tag['value'] = trim($data['value']);</p><p> $last_count = count($last_tag_ar)-1;<br
/> $last_tag_ar[$last_counter_in_tag[$data['level']]++] = $new_tag;<br
/> break;<br
/> case 'close':<br
/> $last_tag_ar =&amp; $parents[$data['level']];<br
/> break;<br
/> default:<br
/> break;<br
/> };<br
/> }<br
/> return $xml_array;<br
/> }</p><p> //<br
/> // use this to get node of tree by path with '/' terminator<br
/> //<br
/> function wp_get_value_by_path($__xml_tree, $__tag_path)<br
/> {<br
/> $tmp_arr =&amp; $__xml_tree;<br
/> $tag_path = explode('/', $__tag_path);<br
/> foreach($tag_path as $tag_name)<br
/> {<br
/> $res = false;<br
/> foreach($tmp_arr as $key =&gt; $node)<br
/> {<br
/> if(is_int($key) &amp;&amp; $node['name'] == $tag_name)<br
/> {<br
/> $tmp_arr = $node;<br
/> $res = true;<br
/> break;<br
/> }<br
/> }<br
/> if(!$res)<br
/> return false;<br
/> }<br
/> return $tmp_arr;<br
/> }</p><p> function getRank($url)<br
/> {<br
/> $arr = $this-&gt;wp_xml2array($this-&gt;alexa_address.$url);<br
/> $arr2= $this-&gt;wp_get_value_by_path($arr, 'ALEXA');</p><p> $arr3=($arr2[2][0]['attributes']);<br
/> $rank=$arr3['TEXT'];</p><p> $rank=($rank=='' ? 'Not ranked yet' : $rank);</p><p> return $rank;<br
/> }<br
/> }<br
/> </code></p><p>Call using this:</p><p><code><br
/> $alexa = new Alexa();</p><p>$rank = $alexa-&gt;getRank(str_replace('http://', '', $url));<br
/> </code></p> ]]></content:encoded> </item> <item><title>By: Keshabraj</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-22137</link> <dc:creator>Keshabraj</dc:creator> <pubDate>Wed, 29 Dec 2010 01:57:03 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-22137</guid> <description>similar mean
+1,+2 or -1 , -2 ranking website list.like my site alexa rank is 4445
similar site for my site is
aaa.com - 4442
bbb.com - 4443
aac.com - 4444
aab.com - 4446
aax.com - 4447
aad.com - 4448</description> <content:encoded><![CDATA[<p>similar mean<br
/> +1,+2 or -1 , -2 ranking website list.</p><p>like my site alexa rank is 4445<br
/> similar site for my site is<br
/> aaa.com &#8211; 4442<br
/> bbb.com &#8211; 4443<br
/> aac.com &#8211; 4444<br
/> aab.com &#8211; 4446<br
/> aax.com &#8211; 4447<br
/> aad.com &#8211; 4448</p> ]]></content:encoded> </item> <item><title>By: Keshabraj</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-22136</link> <dc:creator>Keshabraj</dc:creator> <pubDate>Wed, 29 Dec 2010 01:51:46 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-22136</guid> <description>Hi, I have a question.
suppose I am displaying xml alexa rank in my webpage, how do I display list of &quot;websites&quot; similar to my alexa rank.anticipate for your response.thank you..</description> <content:encoded><![CDATA[<p>Hi, I have a question.<br
/> suppose I am displaying xml alexa rank in my webpage, how do I display list of &#8220;websites&#8221; similar to my alexa rank.</p><p>anticipate for your response.</p><p>thank you..</p> ]]></content:encoded> </item> <item><title>By: snowsh</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-21447</link> <dc:creator>snowsh</dc:creator> <pubDate>Mon, 29 Nov 2010 18:19:31 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-21447</guid> <description>&lt;code&gt;−−−−&lt;/code&gt;</description> <content:encoded><![CDATA[<p><code></p><p>−</p><p>−</p><p>−</p><p>−</p><p></code></p> ]]></content:encoded> </item> <item><title>By: snowsh</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-21446</link> <dc:creator>snowsh</dc:creator> <pubDate>Mon, 29 Nov 2010 18:19:16 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-21446</guid> <description>so this is the xml output: i hope! if not you can see it athttp://data.alexa.com/data?cli=10&amp;dat=snbamz&amp;url=snowsh.com−−−−</description> <content:encoded><![CDATA[<p>so this is the xml output: i hope! if not you can see it at</p><p><a
href="http://data.alexa.com/data?cli=10&#038;dat=snbamz&#038;url=snowsh.com" rel="nofollow">http://data.alexa.com/data?cli=10&#038;dat=snbamz&#038;url=snowsh.com</a></p><p>−</p><p>−</p><p>−</p><p>−</p> ]]></content:encoded> </item> <item><title>By: snowsh</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-21445</link> <dc:creator>snowsh</dc:creator> <pubDate>Mon, 29 Nov 2010 18:17:42 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-21445</guid> <description>hmm that didnt work to well!</description> <content:encoded><![CDATA[<p>hmm that didnt work to well!</p> ]]></content:encoded> </item> <item><title>By: snowsh</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-21444</link> <dc:creator>snowsh</dc:creator> <pubDate>Mon, 29 Nov 2010 18:16:51 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-21444</guid> <description>hmmm....i can see all the XML:
&lt;code&gt;&lt;/code&gt;
I noticed some errors in the function set() so removed the number format operator.
It returns the back links, but not the RANK or REACH value, which is present in the actual XML...my updated class and call:
&lt;code&gt;
//
/* the alexa rank class */
class alexa
{
/* initial vars */
var $xml;
var $values;
var $alexa_address;/* the constructor */
function alexa($alexa_address,$domain)
{
$this-&gt;alexa_address = $alexa_address;
$this-&gt;xml = $this-&gt;get_data($domain);
$this-&gt;set();
}/* gets the xml data from Alexa */
function get_data($domain)
{
$url = $this-&gt;alexa_address.&#039;http://&#039;.$domain;
$xml = simplexml_load_file($url) or die(&#039;Cannot retrieve feed&#039;);
return $xml;
}/* set values in the XML that we want */
function set()
{
$this-&gt;values[&#039;rank&#039;] = ($this-&gt;xml-&gt;SD-&gt;POPULARITY[&#039;TEXT&#039;] ? ($this-&gt;xml-&gt;SD-&gt;POPULARITY[&#039;TEXT&#039;]) : 0);
$this-&gt;values[&#039;owner&#039;] = ($this-&gt;xml-&gt;SD-&gt;OWNER[&#039;NAME&#039;] ? ($this-&gt;xml-&gt;SD-&gt;OWNER[&#039;NAME&#039;]) : 0);
$this-&gt;values[&#039;email&#039;] = ($this-&gt;xml-&gt;SD-&gt;EMAIL[&#039;ADDR&#039;] ? ($this-&gt;xml-&gt;SD-&gt;EMAIL[&#039;ADDR&#039;]) : 0);
$this-&gt;values[&#039;reach&#039;] = ($this-&gt;xml-&gt;SD-&gt;REACH[&#039;RANK&#039;] ? ($this-&gt;xml-&gt;SD-&gt;REACH[&#039;RANK&#039;]) : 0);
$this-&gt;values[&#039;linksin&#039;] = ($this-&gt;xml-&gt;SD-&gt;LINKSIN[&#039;NUM&#039;] ? ($this-&gt;xml-&gt;SD-&gt;LINKSIN[&#039;NUM&#039;]) : 0);
}/* returns the requested value */
function get($value)
{
return (isset($this-&gt;values[$value]) ? $this-&gt;values[$value] : &#039;&quot;&#039;.$value.&#039;&quot; does not exist.&#039;);
}
}
echo &quot;&quot;;
echo &quot;Alexa rank details: &quot;;/* retrieve &amp; display rank */
$alexa_connector = new alexa(&#039;http://data.alexa.com/data?cli=10&amp;dat=snbamz&amp;url=&#039;,&#039;google.com&#039;); // domain only!
echo &#039;Rank :: &#039;.$alexa_connector-&gt;get(&#039;rank&#039;).&quot;&quot;; // returns 118
echo $alexa_connector-&gt;get(&#039;owner&#039;);
echo &#039;Reach :: &#039;.$alexa_connector-&gt;get(&#039;reach&#039;).&quot;&quot;; // returns 95
echo $alexa_connector-&gt;get(&#039;email&#039;);
echo &#039;Links In :: &#039;.$alexa_connector-&gt;get(&#039;linksin&#039;).&quot;&quot;; // returns 34,414
echo &quot;&quot;;
//
&lt;/code&gt;Any ideas?</description> <content:encoded><![CDATA[<p>hmmm&#8230;.</p><p>i can see all the XML:<br
/> <code></p><p></code><br
/> I noticed some errors in the function set() so removed the number format operator.<br
/> It returns the back links, but not the RANK or REACH value, which is present in the actual XML&#8230;</p><p>my updated class and call:<br
/> <code><br
/> //<br
/> /* the alexa rank class */<br
/> class alexa<br
/> {<br
/> /* initial vars */<br
/> var $xml;<br
/> var $values;<br
/> var $alexa_address;</p><p> /* the constructor */<br
/> function alexa($alexa_address,$domain)<br
/> {<br
/> $this-&gt;alexa_address = $alexa_address;<br
/> $this-&gt;xml = $this-&gt;get_data($domain);<br
/> $this-&gt;set();<br
/> }</p><p> /* gets the xml data from Alexa */<br
/> function get_data($domain)<br
/> {<br
/> $url = $this-&gt;alexa_address.'http://'.$domain;<br
/> $xml = simplexml_load_file($url) or die('Cannot retrieve feed');<br
/> return $xml;<br
/> }</p><p> /* set values in the XML that we want */<br
/> function set()<br
/> {<br
/> $this-&gt;values['rank'] = ($this-&gt;xml-&gt;SD-&gt;POPULARITY['TEXT'] ? ($this-&gt;xml-&gt;SD-&gt;POPULARITY['TEXT']) : 0);</p><p> $this-&gt;values['owner'] = ($this-&gt;xml-&gt;SD-&gt;OWNER['NAME'] ? ($this-&gt;xml-&gt;SD-&gt;OWNER['NAME']) : 0);<br
/> $this-&gt;values['email'] = ($this-&gt;xml-&gt;SD-&gt;EMAIL['ADDR'] ? ($this-&gt;xml-&gt;SD-&gt;EMAIL['ADDR']) : 0);<br
/> $this-&gt;values['reach'] = ($this-&gt;xml-&gt;SD-&gt;REACH['RANK'] ? ($this-&gt;xml-&gt;SD-&gt;REACH['RANK']) : 0);<br
/> $this-&gt;values['linksin'] = ($this-&gt;xml-&gt;SD-&gt;LINKSIN['NUM'] ? ($this-&gt;xml-&gt;SD-&gt;LINKSIN['NUM']) : 0);<br
/> }</p><p> /* returns the requested value */<br
/> function get($value)<br
/> {<br
/> return (isset($this-&gt;values[$value]) ? $this-&gt;values[$value] : '"'.$value.'" does not exist.');<br
/> }<br
/> }<br
/> echo "";<br
/> echo "Alexa rank details: ";</p><p>/* retrieve &amp; display rank */<br
/> $alexa_connector = new alexa('http://data.alexa.com/data?cli=10&amp;dat=snbamz&amp;url=','google.com'); // domain only!<br
/> echo 'Rank :: '.$alexa_connector-&gt;get('rank').""; // returns 118<br
/> echo $alexa_connector-&gt;get('owner');<br
/> echo 'Reach :: '.$alexa_connector-&gt;get('reach').""; // returns 95<br
/> echo $alexa_connector-&gt;get('email');<br
/> echo 'Links In :: '.$alexa_connector-&gt;get('linksin').""; // returns 34,414<br
/> echo "";<br
/> //<br
/> </code></p><p>Any ideas?</p> ]]></content:encoded> </item> <item><title>By: Aydın Yakar</title><link>http://davidwalsh.name/php-alexa-rank-fetcher-xml#comment-21159</link> <dc:creator>Aydın Yakar</dc:creator> <pubDate>Fri, 29 Oct 2010 16:11:50 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/php-alexa-rank-fetcher-xml/#comment-21159</guid> <description>There is a new alexa rank function..http://www.aydinyakar.com/webmaster/alexa-rank-almak.html</description> <content:encoded><![CDATA[<p>There is a new alexa rank function..</p><p><a
href="http://www.aydinyakar.com/webmaster/alexa-rank-almak.html" rel="nofollow">http://www.aydinyakar.com/webmaster/alexa-rank-almak.html</a></p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 3/7 queries in 0.013 seconds using disk: basic
Object Caching 805/805 objects using disk: basic

Served from: davidwalsh.name @ 2012-05-23 16:01:17 -->
