get everything inside/between html tags
what is the best way to get some html elements + values? example:
<div id="abc" class="classs">
<img src="pic1.png" alt="pico">
<img src="pic2.png" alt="nano">
</div>
what I have is the id=abc of the div element. I want to get everything inside the div element like:
class of the div ("classs")
src of the pictures and other data:
src="pic1.png", alt="pico开发者_Python百科"
src="pic2.png", alt="nano"
it should be in an array, object or something. What would you prefer? xpath? regex? xmlobject?
You might want to use PHP Simple HTML DOM Parser
Use this function:
public function innerHTML($DOMnode) {
return preg_replace(
'/^<(\w+)\b.*?>(.*)<\/\1?>/s',
'$2',
$DOMnode->ownerDocument->saveXML($DOMnode)
);
}
精彩评论