tags:

views:

7055

answers:

4

In php I need to get the contents of a url (source) search for a string "maybe baby love you" and if it does not contain this then do x.

+4  A: 

Just read the contents of the page as you would read a file. PHP does the connection stuff for you. Then just look for the string via regex or simple string comparison.

$url = 'http://my.url.com/';
$data = file_get_contents( $url );

if ( strpos( 'maybe baby love you', $data ) === false )
{

    // do something

}
okoman
A: 

Assuming fopen URL Wrappers are on ...

$string = file_get_contents('http://example.com/file.html');
if(strpos ('maybe baby love you', $string) === false){  
    //do X
}
Alan Storm
A: 

If fopen URL wrappers are not enabled, you may be able to use the curl module (see http://www.php.net/curl )

Curl also gives you the ability to deal with authenticated pages, redirects, etc.

Hugh Bothwell
A: 

//The Answer No 3 Is good But a small Mistake in the function strpos() I have correction the code bellow.

$url = 'http://my.url.com/'; $data = file_get_contents( $url );

if ( strpos($data,'maybe baby love you' ) === false ) {

// do something

}

Tarek Ahmed