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
2008-11-09 22:47:48
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
2008-11-09 22:49:07
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
2008-11-10 03:28:21
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
2010-01-11 07:55:20