944,127 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3990
  • PHP RSS
Jun 21st, 2005
0

Find text on an external html site

Expand Post »
Hi all,

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

I was thinking something like -
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sm00nie is offline Offline
4 posts
since Jun 2005
Jun 21st, 2005
0

Re: Find text on an external html site

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jun 21st, 2005
0

Re: Find text on an external html site

Whoops! I see that same article has also been posted as a daniweb code snippet:

http://www.daniweb.com/code/snippet293.html
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Jun 21st, 2005
0

Re: Find text on an external html site

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
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 21st, 2005
0

Re: Find text on an external html site

Oops, stripos() is only available in PHP5, so check out strpos().
http://us2.php.net/manual/en/function.strpos.php
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jun 21st, 2005
0

Re: Find text on an external html site

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sm00nie is offline Offline
4 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse error: parse error, unexpected T_STRING in /home/thei2k9/public_html/includes/f
Next Thread in PHP Forum Timeline: Deleting a foreign cookie





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC