how to use Ko3 get all image tags from a section of HTML?
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
精彩评论