Simple link popularity scrip help
Posted: Wed Feb 02, 2005 9:23 pm
I am attempting to write a link popularity script. I would consider myself to be verry new at php as you will no doubt see from my code. Much of the below code has been scrapped together from various other scripts I have found and a little of my own little stuff.
The problem I am having with the script has to do with adding. The script searches for links to 3 domains (ebay.com, slashdot.org, and purediva.com), from two search engines (google and altavista).
It then reports the link popularity for each domain from both search engines. It seems to do this correctly. I would also like to add the results from both search engines for each domain, to display total link popularity for both search engines combined. I cant seem to get this to work and am hoping one of you geuiness can help...
Any way here is my code
And this is the results
As you can see the total results dont work. I have tried many different ways and I just cant seem to get it to work. The first adds all totals together, and the second only reports the first 2 digits of the total.
If anyone has any ideas on how to get this to work properly, please help me out...
Also if you see anything in this code that would help speed things up or run better let me know. Eventually I'm hoping to add many more search engines to this along with a file upload for procesing domain lists.
Thanks for your time.
Ron
The problem I am having with the script has to do with adding. The script searches for links to 3 domains (ebay.com, slashdot.org, and purediva.com), from two search engines (google and altavista).
It then reports the link popularity for each domain from both search engines. It seems to do this correctly. I would also like to add the results from both search engines for each domain, to display total link popularity for both search engines combined. I cant seem to get this to work and am hoping one of you geuiness can help...
Any way here is my code
Code: Select all
<?
$total=0;
$results = array("ebay.com","slashdot.org","purediva.com");
foreach ($results as $domain) {
// check Yahoo!
$path ="http://search.yahoo.com/search?p=linkdomain%3A".$domain."&ei=UTF-8&fr=fp-tab-web-t&cop=mss&tab=";
if(!file_exists($path)) {
$data = strtolower(implode("", file($path)));
$data = substr($data, strpos($data, "of about")+9, strlen($data));
$data = strip_tags(substr($data, 0, strpos($data, " ")));
if(eregi("[[]]", $data)) {
$results['yahoo'] = array('0', $path);
} else {
$results['yahoo'] = array($data, $path);
$total+=str_replace(',', '', $data);
}
} else {
$results['yahoo'] = array('n/a', $path);
}
// check AltaVista
$path ="http://www.altavista.com/web/results?q=linkdomain%3A".$domain."&kgs=1&kls=0&stq=10";
if(!file_exists($path)) {
$data = strtolower(strip_tags(implode("", file($path))));
$data = substr($data, strpos($data, "altavista found")+15, strlen($data));
$data = trim(substr($data, 0, strpos($data, "results"))); //echo "$data<br>"; // TEST
if(eregi("[[]]", $data)) {
$results['altavista'] = array('0', $path);
} else {
$results['altavista'] = array($data, $path);
$total+=str_replace(',', '', $data);
}
} else {
$results['altavista'] = array('n/a', $path);
}
$enginetotals = number_format($total);
$yahooresults = $results['yahoo'][0];
$yahoodomain = $results['yahoo'][1];
$altavistaresults = $results['altavista'][0];
$altavistadomain = $results['altavista'][1];
$total1 = ("$yahooresults" + "$altavistaresults");
//====PRINT RESULTS
echo ("Domain = <b>$domain</b> has<br>");
echo ("<a href="$yahoodomain">$yahooresults</a> Yahoo! Results<br>");
echo ("<a href="$altavistadomain">$altavistaresults</a> Altavista Results<br>");
echo ("$enginetotals Total Search Engine Results using enginetotals<br>");
echo ("$total1 Total Search Engine results usint total1<br><br>");
}
?>Code: Select all
Domain = ebay.com has
10,100,000 Yahoo! Results
9,720,000 Altavista Results
19,820,000 Total Search Engine Results using enginetotals
19 Total Search Engine results using total1
Domain = slashdot.org has
5,990,000 Yahoo! Results
6,070,000 Altavista Results
31,880,000 Total Search Engine Results using enginetotals
11 Total Search Engine results using total1
Domain = purediva.com has
23 Yahoo! Results
25 Altavista Results
31,880,048 Total Search Engine Results using enginetotals
48 Total Search Engine results using total1If anyone has any ideas on how to get this to work properly, please help me out...
Also if you see anything in this code that would help speed things up or run better let me know. Eventually I'm hoping to add many more search engines to this along with a file upload for procesing domain lists.
Thanks for your time.
Ron