我使用codeigniter,并希望检查内容中是否存在其他url中的url,返回为true,否则为false。
例如,我想查询url http://chat.stackoverflow.com/
,它在页面http://stackoverflow.com/
或没有。
我试过了,它有错误:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://stackoverflow.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
$link="http://chat.stackoverflow.com/";
if(preg_match($link,$contents) && stripos($contents,"chat.stackoverflow")){
echo "yes";
}else{
echo "no";
}
?>
输出为:
警告:preg_match():分隔符不能是/code/O4savv第
行的字母数字或反斜杠无
演示:http://codepad.viper-7.com/O4savv
如何修复?
您需要在正则表达式的模式中添加一个前导和结束的正斜杠。此外,为了避免冲突,请避开正斜杠,正斜杠是您试图匹配的模式的一部分。
$link="/http:'/'/chat.stackoverflow.com/";
http://codepad.viper-7.com/PWMVzl