How do I match an exact string in a webpage in PHP?
We can easily check the match in the string
if (preg_match("/happy/i", "happy is he who has ")) {
echo "match found.";
} else {
echo "match not found.";
}
?>
But how do you check for a match on a web page or specify a URL?
EDIT:
How do I use Regex to find if a specific string exists on a web page? I can extract all the information and display it using the code given in one of the answers.
+2
user244333
a source
to share
3 answers
You can use cURL to grab a webpage and you can parse it with any regular expression! http://www.php.net/manual/en/book.curl.php
+2
a source to share
You can use file_get_contents
Direct from php.net
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
+1
a source to share