954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Find text on an external html site

Hi all,

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

I was thinking something like -

<?php
$fp = fopen('http://www.google.ca', 'r');

if (preg_match('/Google.ca/', print fgets($fp))) {
	echo "match";
} else { 
	echo "no match";
}
?>

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

sm00nie
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

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.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

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

http://www.daniweb.com/code/snippet293.html

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

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
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

Oops, stripos() is only available in PHP5, so check out strpos().
http://us2.php.net/manual/en/function.strpos.php

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 
<?php
$str_result = fopen("http://www.google.ca", "r");
while (!feof($str_result)) {
	$buffer = fgets($str_result, 4096);
	$result = strpos($buffer,"Google.ca");
	echo $result;
}
fclose($str_result);
?>

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 :P

sm00nie
Newbie Poster
4 posts since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You