PHP 7 Website Alexa Global and Country Rank Finder Class in HTML5 & Javascript Full Project For Beginners

PHP 7 Website Alexa Global and Country Rank Finder Class in HTML5 & Javascript Full Project For Beginners
  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be finding alexa rank inside php class. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to create index.php file and copy paste the following code

 

index.php

 

<?php

/*
* @copyright © 2017 WeaveBox.in
*/

function alexaRank($site)
{
    $xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$site);

    $a = $xml->SD[1]->POPULARITY;
    if ($a != null)
    {
        $alexa_rank = $xml->SD[1]->POPULARITY->attributes()->TEXT;
        $alexa_rank = ($alexa_rank==null ? 'No Global Rank' : $alexa_rank);
    } else
    {
        $alexa_rank = 'No Global Rank';
    }
       
    $a1 = $xml->SD[1]->COUNTRY;

    if ($a1 != null)
    {
        $alexa_pop = $xml->SD[1]->COUNTRY->attributes()->NAME;
        $regional_rank = $xml->SD[1]->COUNTRY->attributes()->RANK;
        $alexa_pop = ($alexa_pop==null ? 'None' : $alexa_pop);
        $regional_rank = ($regional_rank==null ? 'None' : $regional_rank);

    } else
    {
        $alexa_pop = 'None';
        $regional_rank = 'None';
    } 
    
    $a2 = $xml->RLS->RL;
    if ($a2 != null)
    {
        $related = array();
        $i = 0;
        foreach($a2 as $ap){
            $related[$i]['title'] = (string)$ap->attributes()->TITLE;
            $related[$i]['href'] = (string)$ap->attributes()->HREF;
            $i++;
        }

    } else
    {
        $related[$i]['title'] = 'None';
        $related[$i]['href'] = 'None';
    }


    return array($alexa_rank,$alexa_pop,$regional_rank,$related);
}

$result = alexaRank("https://codingshiksha.com");

foreach ($result as $value) {
    echo $value, "\n";
}

?>

 

See also  PHP 7 Script to Convert URLs Within Text String into Clickable Links in Browser Full Project For Beginners

So now if you execute the python script by opening it inside the apache browser you will see the following result as shown below

 

 

Now as you can see in the above figure it is showing the alexa global and country rank

Leave a Reply