Page 1 of 1

Query MSN for Backlinks...

Posted: Mon Nov 24, 2008 6:36 pm
by theparamount

Code: Select all

function msnBacklink($sUrl){
    $site_url='http://search.msn.com/results.aspx?q=link%3A+'.($sUrl).'&go=&form=QBRE';
    $site = fopen($site_url,'r');
    while($cont = fread($site,1024657)){
        $total .= $cont;
    }
    fclose($site);
    $match_expression = '/ of (.*) results</span>/';
    preg_match($match_expression,$total,$matches);
    return "<a href='".$site_url."' target='_blank'>".$matches[1]."</a>";
}
I want this code to open up the MSN back link search for a specific url "www.sitename.com" then search that for the number of results and print that out. What is wrong with the code? I got it to work for Google.

Re: Query MSN for Backlinks...

Posted: Mon Nov 24, 2008 10:45 pm
by requinix
It's your code. How about you tell us what's wrong and we'll tell you why.

Let's see... it's getting the number of results but a lot more than just that? A * in a PCRE regular expression is naturally greedy: it'll "eat" as much as it possibly can and still have a match.
If you don't know what that means you should probably learn what your code does rather than blindly use it and assume it's working correctly.

Use .*? instead of just .*.