abroms Posted September 11, 2009 Share Posted September 11, 2009 Ugh, I was really hoping I could get through this project without having to ask for help, but I guess I have to at this point. I'm new at PHP, and this is one of the first scripts I've written, although I did get some help from a tutorial for the basis. I've got another page with just a form that works fine, and it passes the desired search term and your URL that you want to see. The idea is that you enter the URL of your site as it appears in the Cite field in google, and you enter a search term. The script will output a message saying where your site ranks for the term. Here's the code: <?php function getValue($item, $query, $end) { $item = stristr($item, $query); $item = substr($item, strlen($query)); $stop = stripos($item, $end); $val = substr($item, 0, $stop); return $val; } $agent = "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"; $cookie = "/tmp/cookie.txt"; $url = "http://www.google.com/search?q=%searchterm%&;hl=en&start=&num=100"; $searchTerm = urlencode($_GET["term"]); $searchURL = str_replace('%searchterm%', $searchTerm, $url); $i = 0; $ch = curl_init(); //Blah blah I have some curlopt stuff here. If you want it, ask away. $rawdata = curl_exec($ch); $rawdata= strstr($rawdata, "<li class=g>"); $results = explode("<li class=g>", $rawdata); foreach($results as $value){ if(strstr($value, '<div class="s">')){ $data = strstr($value, "<a"); $cite = getValue($data, '<cite>', ' -'); $yourSite = $_GET["site"]; $i++; if($cite==$yourSite){ echo "Your site, '" . $yourSite . "' ranks #" . $i . " for the search term " . $searchTerm . ".<br>"; } } } curl_close($ch); ?> Now here's the problem. I've been testing with the search term 'soccer'. For testing purposes, I search for soccer on google, copy paste a URL from one of the cite fields into the form along with the keyword soccer. However, only some of the results work! For instance, the #1 and #5 results work well, but the #4 result doesn't. Any ideas? Thanks in advance! p.s. general php good practice and tips are greatly appreciated too! Link to comment https://forums.phpfreaks.com/topic/173954-need-help-with-google-ranking-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.