Question

Using php, I'm trying to create a script which will grab all the contents of a url then search within it for a string and echo if the match was found.

Say I have a url (http://www.mydomain.com) and within this url, there is a string stored in it which is also 'http://www.mydomain.com'. I want to grab the contents of http://www.mydomain.com and check if 'http://www.mydomain.com' is present in its source code or not.

Was it helpful?

Solution

try this code

<?php
$homepage = file_get_contents('http://www.mydomain.com/');
if (strpos($homepage,'http://www.mydomain.com/') !== false) {
    echo 'true';
}

enjoy :)

OTHER TIPS

$content = file_get_contents('http://someurl.com');
$pos = strpos($content, 'Some String');
if($pos!==false){
echo 'String Exists';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top