Php 如何在双引号下查找URL

Php 如何在双引号下查找URL,php,regex,parsing,url,preg-match,Php,Regex,Parsing,Url,Preg Match,假设我们加载了这个问题的源代码,并希望在“childUrl旁边找到url。” 或者转到此网站源代码并搜索“childUrl” 试试这个 <?php function extract($url){ $sites_html = file_get_contents("$url"); $html = new DOMDocument(); $$html->loadHTML($sites_html); foreach ($html->load

假设我们加载了这个问题的源代码,并希望在“childUrl旁边找到url。”

或者转到此网站源代码并搜索“childUrl


试试这个

<?php
    function extract($url){
    $sites_html = file_get_contents("$url");
    $html = new DOMDocument();
    $$html->loadHTML($sites_html);

      foreach ($html->loadHTML($sites_html) as $row)
      {
       if($row=="wanted_url") 
       {
         echo $row;
       }
     }
 }
?>

您可以使用正则表达式: 试试这个代码

$matches = [[],[]];
preg_match_all('/\"wanted_url\": \"([^\"]*?)\"/', $sites_html, $matches);
foreach($matches[1] as $match) {
    echo $match;
}


这将打印所有带有通缉url标记的url

解析错误:语法错误,意外的“[”,在C:\wampyou说此文档包含“key”:“value”@Emmanuel立即尝试代码确保$sites\u html包含您所说的url,它们类似于:“key”:“value”,如果它们类似,您可以使用此代码code@hassan提前感谢,,但是如果你能运行完整的代码并检查它,它就不起作用了。我得到了这个错误“可捕获的致命错误:DOMDocument类的对象无法转换为字符串”
$matches = [[],[]];
preg_match_all('/\"wanted_url\": \"([^\"]*?)\"/', $sites_html, $matches);
foreach($matches[1] as $match) {
    echo $match;
}