How would you make PHP search a website for a certain word and then return a true or false?

Is there a function built into php already?

Note sure exaclty how I would use it? Can you explain more please :)

Note sure exaclty how I would use it? Can you explain more please :)

Found this example here http://www.weberdev.com/get_example-4606.html

<?php
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_URL,"http://search.msn.com/results.aspx?q=test&FORM=MSNH");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data1=curl_exec($ch) or die(curl_error());
echo "<font color=black face=verdana size=3>".$data1."</font>";
echo curl_error($ch);
curl_close($ch);
?>

and rather than echoing the data to the page you just use string and array functions to parse and search through the $data1 variable.

thanks for all the help!

Member Avatar for langsor

Also, assuming your server host didn't disable this feature (enabled by default) for security reasons (allow_url_fopen) you can also get the contents of a file via URL with ...

file (returns file as array, split on linebreaks)
fopen (opens read/write/append file-handle)
file_get_contents (returns whole file as string)

Write ups of these functions
file -- http://us.php.net/manual/en/function.file.php
fopen --- http://us.php.net/manual/en/function.fopen.php
file_get_contents -- http://us.php.net/manual/en/function.file-get-contents.php
allow_url_fopen -- http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Just thought you might like to know

<?php
$word = 'search'; // found
//$word = 'phat'; // not found
$file = file_get_contents( 'http://www.google.com' );
if ( preg_match( "/$word/i", $file ) ) {
  print "word: $word";
} else {
  print "phat";
}
?>
commented: Awesome! +2

Even better, this will make my job 10 times easier.

Also, assuming your server host didn't disable this feature (enabled by default) for security reasons (allow_url_fopen) you can also get the contents of a file via URL with ...

file (returns file as array, split on linebreaks)
fopen (opens read/write/append file-handle)
file_get_contents (returns whole file as string)

Write ups of these functions
file -- http://us.php.net/manual/en/function.file.php
fopen --- http://us.php.net/manual/en/function.fopen.php
file_get_contents -- http://us.php.net/manual/en/function.file-get-contents.php
allow_url_fopen -- http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

Just thought you might like to know

<?php
$word = 'search'; // found
//$word = 'phat'; // not found
$file = file_get_contents( 'http://www.google.com' );
if ( preg_match( "/$word/i", $file ) ) {
  print "word: $word";
} else {
  print "phat";
}
?>

Even better, this will make my job 10 times easier.

Ya, I guess Curl is a bit overkill for what you want to do with it, but it is a good thing to learn though as the options are limitless.
If you ever decide to play with it, here is a pretty good tutorial:
http://www.phpbuilder.com/columns/ian_gilfillan20050525.php3

Member Avatar for langsor

Ya, I guess Curl is a bit overkill for what you want to do with it, but it is a good thing to learn though as the options are limitless.
If you ever decide to play with it, here is a pretty good tutorial:
http://www.phpbuilder.com/columns/ian_gilfillan20050525.php3

Thanks R0bb0b,

I've actually been avoiding learning CURL since it seems complicated, and I'm lazy, but I know I should figure it out too. I bookmarked that tutorial.

Cheers

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.