Find text on an external html site

Reply

Join Date: Jun 2005
Posts: 4
Reputation: sm00nie is an unknown quantity at this point 
Solved Threads: 0
sm00nie sm00nie is offline Offline
Newbie Poster

Find text on an external html site

 
0
  #1
Jun 21st, 2005
Hi all,

Would anyone know how to search an external html file for a work or phrase ?

I was thinking something like -
  1. <?php
  2. $fp = fopen('http://www.google.ca', 'r');
  3.  
  4. if (preg_match('/Google.ca/', print fgets($fp))) {
  5. echo "match";
  6. } else {
  7. echo "no match";
  8. }
  9. ?>
Unfortunently, that doesn't work, but you get the jist of what I'm attempting.

Any ideas, suggestions, code would be greatfully appreciated,

Thanks,
Smoonie
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Find text on an external html site

 
0
  #2
Jun 21st, 2005
I think what you're describing is called "screen scraping". There's an article on my site specifically about PHP screen scraping: http://www.tgreer.com/class_http_php.html

Of course, support DaniWeb. If you'd like to discuss that article, you can do so in this thread. The article author is also a DaniWeb member.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Find text on an external html site

 
0
  #3
Jun 21st, 2005
Whoops! I see that same article has also been posted as a daniweb code snippet:

http://www.daniweb.com/code/snippet293.html
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Find text on an external html site

 
0
  #4
Jun 21st, 2005
I'm the author of those articles and the class. It is posted here on Daniweb, but the article version at www.tgreer.com provides a lot more in-depth explanation of usage.

sm00nie, check out PHP's stripos() function. It is what you are looking for I believe.
http://us2.php.net/manual/en/function.stripos.php
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Find text on an external html site

 
0
  #5
Jun 21st, 2005
Oops, stripos() is only available in PHP5, so check out strpos().
http://us2.php.net/manual/en/function.strpos.php
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 4
Reputation: sm00nie is an unknown quantity at this point 
Solved Threads: 0
sm00nie sm00nie is offline Offline
Newbie Poster

Re: Find text on an external html site

 
0
  #6
Jun 21st, 2005
  1. <?php
  2. $str_result = fopen("http://www.google.ca", "r");
  3. while (!feof($str_result)) {
  4. $buffer = fgets($str_result, 4096);
  5. $result = strpos($buffer,"Google.ca");
  6. echo $result;
  7. }
  8. fclose($str_result);
  9. ?>
Now I can add some error checking and I'm golden with this little snip.
Thanks fellas, I was starting to pull out what little hair I have left
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC