Issue with querry to Google

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Issue with querry to Google

Post by someguyhere »

http://www.wildfiremarketinggroup.com/A ... ndexed.php

The following code does not seem to return the corect data. Is there somethign obvious that I'm mising? Am I passing the querry to Google properly?

Code: Select all

<?php
$return=file_get_contents("http://www.google.com/search?hl=en&rlz=1T4ADBF_enUS262US262&q=site%3Ahttp%3A%2F%2Fwww.msn.com");
preg_match("/of about (.*?) from/",$return,$output); $output=$output[1];
echo'Pages indexed: '.$output;
?>
Also, once I get this working, I plan to have it display the pages indexed for multiple sites. I was planning to load them into an array from a flat file - is that the right approach? (the array part I have already sorted out thanks to the people here on this forum).

Thanks in advance!
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Issue with querry to Google

Post by someguyhere »

Disregard the number of pages...it seems to be showing the correct number now. I would still like to know if I am passing the querry to Google the most effective/efficient way though.
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: Issue with querry to Google

Post by someguyhere »

someguyhere wrote:http://www.wildfiremarketinggroup.com/A ... ndexed.php

Am I passing the querry to Google properly?

Code: Select all

<?php
$return=file_get_contents("http://www.google.com/search?hl=en&rlz=1T4ADBF_enUS262US262&q=site%3Ahttp%3A%2F%2Fwww.msn.com");
preg_match("/of about (.*?) from/",$return,$output); $output=$output[1];
echo'Pages indexed: '.$output;
?>
Also, once I get this working, I plan to have it display the pages indexed for multiple sites. I was planning to load them into an array from a flat file - is that the right approach? (the array part I have already sorted out thanks to the people here on this forum).

Thanks in advance!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Issue with querry to Google

Post by onion2k »

I really hate it when people bump their topics. Anyway...

No, you aren't doing this in the most efficient way you could be. Your PHP script will stop until the page from Google has been loaded. That's not really a problem if you're only checking a single site but if you're checking lots of sites the script is going to be really, really slow. Curl, or curl multi, is a better approach (in my opinion).

Your script also suffers from a reliance on Google's page format. If they change the wording, or even just the layout, your script will break.
Post Reply