Note that there are some explanatory texts on larger screens.

plurals
  1. POAlways returning 0, Google SERP Checker
    text
    copied!<p>My function searches google for the specific keyword and then checks for the site and then returns the what position it is on google (its for my seo dashboard) but it always return's 0, hopefully some fresh eyes can find the faults</p> <pre><code>&lt;?php function GoogleSerp($searchquery, $searchurl){ if(!empty($searchquery) &amp;&amp; !empty($searchurl)) { $query = str_replace(" ","+",$searchquery); $query = str_replace("%26","&amp;",$query); // How many results to search through. $total_to_search = 50; // The number of hits per page. $hits_per_page = 10; // Obviously, the total pages / queries we will be doing is // $total_to_search / $hits_per_page // This will be our rank $position = 0; // This is the rank minus the duplicates $real_position = 0; $found = NULL; $lastURL = NULL; for($i=0;$i&lt;$total_to_search &amp;&amp; empty($found);$i+=$hits_per_page) { // Open the search page. // We are filling in certain variables - // $query,$hits_per_page and $start. // $filename = "http://www.google.co.uk/xhtml?q=$query&amp;start=$i&amp;sa=N"; $filename = "http://www.google.co.uk/m?q=$query&amp;num=$hits_per_page&amp;filter=0&amp;start=$i&amp;sa=N"; $file = fopen($filename, "r"); if (!$file) { return "error"; } else { // Now load the file into a variable line at a time while (!feof($file)) { $var = fgets($file, 1024); // Try and find the font tag google uses to show the site URL if(eregi("&lt;span class=\"c\"&gt;(.*)&lt;/span&gt;",$var,$out)) { // If we find it take out any &lt;B&gt; &lt;/B&gt; tags - google does // highlight search terms within URLS $out[1] = strtolower(strip_tags($out[1])); // Get the domain name by looking for the first / $x = strpos($out[1],"/"); // and get the URL $url = substr($out[1],0,$x); $url = str_replace("/","",$url); $position++; // If you want to see the hits, set $trace to something // if($trace)return($url."&lt;br&gt;"); // If the last result process is the same as this one, it // is a nest or internal domain result, so don't count it // on $real_position if(strcmp($lastURL,$url)&lt;&gt;0)$real_position++; $lastURL = $url; // Else if the sites match we have found it!!! if(strcmp($searchurl,$url)==0) { $found = $position; // We quit out, we don't need to go any further. break; } } } } fclose($file); } if($found) { $result = $real_position; }else{ $result = 0; } } return $result; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload