开发者

how to use Ko3 get all image tags from a section of HTML?

开发者 https://www.devze.com 2023-01-14 21:09 出处:网络
how to use K开发者_如何学编程o3 or PHP get all image tags from a section of HTML?I would use xPath with SimpleXml or DOMDocument depending on my needs, although Kohana might offer something better lik

how to use K开发者_如何学编程o3 or PHP get all image tags from a section of HTML?


I would use xPath with SimpleXml or DOMDocument depending on my needs, although Kohana might offer something better like Zend does with Zend_Dom_Query or Symfony does with sfWebBrowser (both of which let you use a querys similar to jQuery's css selectors). Anyhow with simple xml it might look like the following:

// we will assume you want the images in a div with the id "ihaveimages"

$dom = new SimpleXmlElement($htmlString);
$images = $dom->xpath("//div[@id='ihaveimages']/img");

foreach($images as $image)
{
  echo $image->asXml();
}

More info on xPath

0

精彩评论

暂无评论...
验证码 换一张
取 消