I have been searching and searching and I cant seem to find any code on what I am trying to do. Basically all I want is a function that will look at a web page and tell me if a phrase is present or not. I think I would have to use a regular expresion but that stuff just confuses me. For example Function If phrase "google" is on www.google.com else Just something that simple. I know it can be done in just a few lines of code but I am clueless. Any help?
1. Grab the content with file_get_contents 2. If regExp confuses you and you just need to know whether it's on there or not, just use if (strpos("google", $fetched_data)) { echo 'hooray!'; }
Sounds good. But I forgot to mention I am learning PHP and I need stuff spelled out more. I know you love to help people so if can take 3.5 minutes and write the code I will declare today a holiday in your name.
LOL... You're lucky then... (Quick before Mad4 beats me) $url_to_grab = "http://www.digitalpoint.com"; $fetched_data = file_get_contents($url_to_grab); //http://uk2.php.net/file_get_contents $looking_for = "Shawn"; if (strpos($fetched_data, $looking_for)) { // http://uk2.php.net/manual/en/function.strpos.php echo 'Shawn is found on ' . $url_to_grab; } else { echo 'No go! Try again!'; } PHP:
Tested and works like a charm. Congratulations and I am sorry christopher columbus but you now have to share your holiday with T0PS3O!
Thanks klown I've already been thinking about improvements. We can honour robots.txt and if we crawl multiple pages of the same domain, we will slow down by using sleep(); Caching can be implemented and we can use Curl as well. We can add reporting, stats and graphs on performance. G
I might call strip_tags on the fetched data before searching for the string so that you won't search for the string among HTML comments/code. Also strpos will return 0 if the string is found at the very beginning of the fetched data, and returns boolean false if it's not found. You can do if (strpos ($feched_data, $string) !== false) { ... }