PHP获取URL内容并搜索字符串
在php中,我需要获取url源搜索的内容,搜索字符串“baby love you”,如果它不包含此内容,则执行x。就像读取文件一样读取页面内容。PHP为您提供连接功能。然后通过正则表达式或简单的字符串比较查找字符串PHP获取URL内容并搜索字符串,php,Php,在php中,我需要获取url源搜索的内容,搜索字符串“baby love you”,如果它不包含此内容,则执行x。就像读取文件一样读取页面内容。PHP为您提供连接功能。然后通过正则表达式或简单的字符串比较查找字符串 $url = 'http://my.url.com/'; $data = file_get_contents( $url ); if ( strpos( 'maybe baby love you', $data ) === false ) { // do somethin
$url = 'http://my.url.com/';
$data = file_get_contents( $url );
if ( strpos( 'maybe baby love you', $data ) === false )
{
// do something
}
只需像读取文件一样读取页面内容。PHP为您提供连接功能。然后通过正则表达式或简单的字符串比较查找字符串
$url = 'http://my.url.com/';
$data = file_get_contents( $url );
if ( strpos( 'maybe baby love you', $data ) === false )
{
// do something
}
假设fopen URL包装器处于打开状态
$string = file_get_contents('http://example.com/file.html');
if(strpos ('maybe baby love you', $string) === false){
//do X
}
假设fopen URL包装器处于打开状态
$string = file_get_contents('http://example.com/file.html');
if(strpos ('maybe baby love you', $string) === false){
//do X
}
如果未启用fopen URL包装器,则可以使用curl模块,请参阅
Curl还使您能够处理经过身份验证的页面、重定向等。如果未启用fopen URL包装器,您可以使用Curl模块,请参阅
//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
}
Curl还使您能够处理经过身份验证的页面、重定向等。这应该是strpos$data,“也许宝贝爱你”;这应该是strpos$data,“也许宝贝爱你”;
//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
}