Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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 在HTML源代码中搜索字符串';cdn';要求卷曲后_Php_Curl_Preg Match_Preg Match All_Stripos - Fatal编程技术网

Php 在HTML源代码中搜索字符串';cdn';要求卷曲后

Php 在HTML源代码中搜索字符串';cdn';要求卷曲后,php,curl,preg-match,preg-match-all,stripos,Php,Curl,Preg Match,Preg Match All,Stripos,我想尝试建立一个网站是否使用CDN。这有点含糊不清,但我只想检查源代码是否包含“cdn”,基于此,我可以假设该站点正在使用cdn。-我知道很糟糕。不确定是否还有其他方法 这就是我所拥有的 $url = $_GET['url']; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $subject = curl_

我想尝试建立一个网站是否使用CDN。这有点含糊不清,但我只想检查源代码是否包含“cdn”,基于此,我可以假设该站点正在使用cdn。-我知道很糟糕。不确定是否还有其他方法

这就是我所拥有的

$url = $_GET['url'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$subject = curl_exec($ch);
curl_close($ch);

//cdn check
if (preg_match("/(cdn)/", $subject)) {
    $cdn = true;
} else {
    $cdn = false;
}
它在检查包含以下HTML的网站时起作用:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />

但在检查包含此HTML的网站时失败:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css" />

Dispite“cdn”同时位于这两个位置


有什么想法吗?谢谢

第二个网站返回了html,但是链接在页面加载后被动态插入,因此没有通过curl返回html

这是因为第二个网站返回了
curl\u exec
返回
false
。使用
var\u dump($subject)嗨,我有一些错误处理,它没有返回false。我正在检查是否有其他Sting有效。使用硬编码的第二个字符串运行
preg\u match()
。因此,您无法从curl请求中获取HTML,或者该链接文本可能是在页面加载后动态生成的。啊!链接文本是动态生成的,这就是为什么我可以找到它。非常感谢。