error parse new
本文由我司收集整编,推荐下载,如有疑问,请与我司联系如何使用DomDocument从给定的html中获取href,Image src,title 如何使用DomDocument从给定的html中获取href,Image src,title[英]How can I get a href,Image src,title from given html using DomDocument Need to get a href value,img src and span ie Title . I am parsing this using domDocument but not getting exact result.
 需要获得href值,img src和span即标题。我使用domDocument解析这个但没有得到确切的结果。
  Code:
 码:
 $doc = new DomDocument; $doc- validateOnParse = true; $doc- loadHtml(file_get_contents($url)); $xpath = new DOMXPath($doc);$nodes = $xpath- query(‘//[@id=“testid”]/ul/li’); 1
 Here we are using DOMDocument. For now i am gathering a’s href and img’s src, you can add further more tags you want.
 这里我们使用DOMDocument。现在我正在收集一个href和img的src,你可以添加更多你想要的标签。
  Try this code snippet here
 在此处尝试此代码段
 $domDocument = new DOMDocument();$domDocument- loadHTML($string);$domXPath = new DOMXPath($domDocument);$results = $domXPath- query(“//div[@id=‘testid’]”);//querying div with id=“testid”$results = $domXPath- query(“//a|//img”,$results- item(0))//querying resultant div for    a and img$data=array();foreach($results as $result){ if($result- tagName==“a”)//checking for anchor tags $data[“a”][]=array( “href”= $result- getAttribute(“href”), “title”= $result- getAttribute(“title”) elseif($result- tagName==“img”)//checking for image tags $data[“img”][]=$result- getAttribute(“src”);print_r($data); 0

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。