We can easily check for a match in a string
if (preg_match("/happy/i", "happy is he who has ")) {
echo "match found.";
} else {
echo "match not found.";
}
?>
But how to check for the occurrence of match in a webpage or given a url?
EDIT:
How to use Regex to find if a specific string exists within a webpage? I am able to extract all the information and display it using the code given in one of answers.
As Rodolphie already said, using cURL is possibly the best way to fetch a remote page. You really don't need to use regexp to check if the text contains a string, this will do it:
if (strpos($urlContents, $needle) !== FALSE) {
echo "match found";
}
You can use cURL to grab a webpage, and you may parse it with any regular expression you wish ! http://www.php.net/manual/en/book.curl.php
You could use file_get_contents
Straight from php.net
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>