Hi all,

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

I was thinking something like -

$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,


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.

$str_result = fopen("http://www.google.ca", "r");
while (!feof($str_result)) {
	$buffer = fgets($str_result, 4096);
	$result = strpos($buffer,"Google.ca");
	echo $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

This article has been dead for over six months. Start a new discussion instead.