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

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.

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

<?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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.