Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过php(codeigniter)在内容(页面)和其他url中检查url_Php_Codeigniter_Curl - Fatal编程技术网

通过php(codeigniter)在内容(页面)和其他url中检查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(

我使用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():第8行的/code/O4savv中的分隔符不能是字母数字或反斜杠
没有

演示:


如何修复它?

您需要在正则表达式的模式中添加前导和结尾的正斜杠。另外,避免使用正斜杠,这是您试图匹配的模式的一部分,以避免冲突

$link="/http:\/\/chat.stackoverflow.com/"; 

与codeigniter无关……您能将其更改为codeigniter吗?如何?为什么输出为
?(除非不存在
http://chat.stackoverflow.com/
第页中的
http://stackoverflow.com/
?)@Kate Wintz我错了,只要删除最后一个转义的正斜杠,你就可以开始了。