Domanda

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.

È stato utile?

Soluzione

try this code

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

enjoy :)

Altri suggerimenti

$content = file_get_contents('http://someurl.com');
$pos = strpos($content, 'Some String');
if($pos!==false){
echo 'String Exists';
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top