Just noticed you never called the function. Also you can't have anything after a return statement.

Code: 
<?php
function alexaRank($domain){
    $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
    $search_for = '<POPULARITY URL';
    if ($handle = @fopen($remote_url, "r")) {
        while (!feof($handle)) {
            $part .= fread($handle, 100);
            $pos = strpos($part, $search_for);
            if ($pos === false)
            continue;
            else
            break;
        }
        $part .= fread($handle, 100);
        fclose($handle);
    }
    $str = explode($search_for, $part);
    $str = array_shift(explode('"/>', $str[1]));
    $str = explode('TEXT="', $str);

    return $str[1];
}
echo alexaRank('test.com');?>
Dman Reviewed by Dman on . Showing alexa using HTML code I need to show alexa of a given domain using HTML code in phpld 2. Let's assume $url as the site url whose alexa I need. Rating: 5