Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Posting string & searching returned data form string

    hi guys

    ok im well and truly stumped ..

    been working on this now for a while and just deleted files because i couldnt get it working

    basically i want to post a string value to google
    then i want it to search the returned results for a string value and return the position

    anyone able to help and i'll happily paypal you some cash as need it quite urgently

    thanks in advance

  • #2
    New Coder
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here is the code im playing with

    PHP Code:
    <?php 


    $searchquery 
    "keyword";
    $searchurl "www.domain.com";

    if(!empty(
    $searchquery) && !empty($searchurl))
    {
        
    $query str_replace(" ","+",$searchquery);    
        
    $query str_replace("%26","&",$query);    

        
    $total_to_search 100;

        
    $hits_per_page   10;
        
        
    $position      0;
        
        
    $real_position 0;

        
    $found   NULL;
        
    $lastURL NULL;

        for(
    $i=0;$i<$total_to_search && empty($found);$i+=$hits_per_page)
        {
            
    $filename "http://www.google.co.uk/#hl=en&gs_rn=14&gs_ri=psy-ab&cp=$hits_per_page".
                        
    "&gs_id=8t&xhr=t&q=$query&es_nrs=true&pf=p&safe=off&sclient=psy-ab&oq=$query".
                        
    "&gs_l=&pbx=1&bav=on.2,or.r_qf.";

            
    $file fopen($filename"r");
            if (!
    $file
            {
                echo 
    "<p>Unable to open remote file $filename.\n";
            }
            else
            {
                while (!
    feof($file))
                {
                    
    $var fgets($file1024);

                    if(
    eregi("<font color=#008000>(.*)</font><nobr>",$var,$out))
                    {
                        
    $out[1] = strtolower(strip_tags($out[1]));

                        
    $x strpos($out[1],"/");

                        
    $url substr($out[1],0,$x);

                        
    $position++;


                        if(
    $trace)print($url."<br>");

                        if(
    strcmp($lastURL,$url)<>0)$real_position++;

                        
    $lastURL $url;

                        if(
    strcmp($searchurl,$url)==0)
                        {
                            
    $found $position;
                                                
                            break;
                        }    
                    }
                }
            }
            
    fclose($file);    
        }

        if(
    $found)
        {
            print(
    "The URL $searchurl is at position $found ".
                  
    "( $real_position ) for the term $searchquery");
        }
    }
    ?>

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    google "curl google results"
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •