通过php(codeigniter)在内容(页面)和其他url中检查url
我使用codeigniter,希望检查内容中是否存在其他url中的url,返回值为true,否则返回值为false 例如,我想查看url通过php(codeigniter)在内容(页面)和其他url中检查url,php,codeigniter,curl,Php,Codeigniter,Curl,我使用codeigniter,希望检查内容中是否存在其他url中的url,返回值为true,否则返回值为false 例如,我想查看urlhttp://chat.stackoverflow.com/在第http://stackoverflow.com/或否 我试过了,它有错误: <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://stackoverflow.com/'); curl_setopt(
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():第8行的/code/O4savv中的分隔符不能是字母数字或反斜杠
没有 演示:
如何修复它?您需要在正则表达式的模式中添加前导和结尾的正斜杠。另外,避免使用正斜杠,这是您试图匹配的模式的一部分,以避免冲突
$link="/http:\/\/chat.stackoverflow.com/";
与codeigniter无关……您能将其更改为codeigniter吗?如何?为什么输出为
否
?(除非不存在http://chat.stackoverflow.com/
第页中的http://stackoverflow.com/
?)@Kate Wintz我错了,只要删除最后一个转义的正斜杠,你就可以开始了。