Hi I need a spot of help from a knowledgeable php’er please. What I would like to do is have a function check for a backlink from dmoz and the yahoo dir. This is the current structure I have for checking backlinks through yahoo site explorer. /* Function to check Yahoo Backlinks */ function yahoo_back($url){ $site = fopen('http://siteexplorer.search.yahoo.com/search?p='.urlencode($url).'&bwm=i&bwmf=a&bwms=p','r'); while($cont = fread($site,1024657)){ $total .= $cont; } fclose($site); $match_expression = '/of about <strong>(.*) <\/strong>/Us'; preg_match($match_expression,$total,$matches); return $matches[1]; } Code (markup): What I need is to return a ‘0’ or ‘1’ on unsuccessful/successful find when checking the following domains… http://search.dmoz.org/cgi-bin/search?search= http://search.yahoo.com/search/dir?p= Cheers
if(preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($szSiteContent))) { return false; } return true; PHP: Or something to the same effect.
Thanks for your help! I have tried the following but I only get a positive '1' result never a negative. Any ideas what I may have wrong? /* Function to check Dmoz Backlink */ function getDmoz () { $site = fopen('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url).'','r'); if(preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($szSiteContent))) { $value = false; } else { $value = true; } return $value; } PHP:
Couple of problems with the code; I cleaned it up a little. You were calling fopen(), but not following it with an fread and fclose to actually get the site content. Replaced all of that with file_get_contents() You weren't passing in the $url paramter You passed a non-existent $szSiteContent variable to stript_tags(); replaced it with $site, which is what you intended Tested and works. function getDmoz($url) { $site = file_get_contents('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url),'r'); return preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($site)) ? false : true; } PHP:
code is: function getDmoz($url) { $site = file_get_contents('http://search.dmoz.org/cgi-bin/search?search='.urlencode($url),'r'); return preg_match('/.*No Open Directory Project results found.*/iU', strip_tags($site)) ? false : true; }