Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4031384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:35:26+00:00 2026-05-20T11:35:26+00:00

My function searches google for the specific keyword and then checks for the site

  • 0

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

<?php
function GoogleSerp($searchquery, $searchurl){
if(!empty($searchquery) && !empty($searchurl))
{
    $query = str_replace(" ","+",$searchquery);
    $query = str_replace("%26","&",$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<$total_to_search && 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&start=$i&sa=N";
        $filename = "http://www.google.co.uk/m?q=$query&num=$hits_per_page&filter=0&start=$i&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("<span class=\"c\">(.*)</span>",$var,$out))
                {

// If we find it take out any <B> </B> 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."<br>");

// 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)<>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;
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:35:27+00:00Added an answer on May 20, 2026 at 11:35 am

    Try urlencode() instead of the two replaces on the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which searches an STL container then returns the iterator when
I have a Flex application that calls a function which searches a large document
My google searches on how to split a string on a delimiter have resulted
I have searched Google and Stackoverflow for this question, but I still don't understand
How can I find the parameters of an undocumented Dll function? I have searched
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _
function Submit_click() { if (!bValidateFields()) return; } function bValidateFields() { /// <summary>Validation rules</summary> ///
function main() { Hello(); } function Hello() { // How do you find out
function AddTheatres() { Services.AdminWebServices.AddTheatresSVC(oTheatres, OnSuccessTheatres, OnError, OnTimeOut); } function OnSuccessTheatres(result1) { Services.AdminWebServices.AddTicketPricesSVC(oTicketPrices, OnSuccessTicketPrices, OnError,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.