S
H
A
R
E

Friday, September 23, 2011

Easy Way Convert HTML to XML in PHP DOMdocument

You know that this tag is not valid for XML DOM Document. if you will to load content from HTML page and you need to convert it to XML this img tag will be a big trouble. Let me to fix this problem.


See this sample code and you will understand how I can do it :-)


$ret = '';
$x = new DOMDocument;
$x->loadHTML($ret);
$x->loadXML($x->saveXML());
echo $x->childNodes->item(1)->childNodes->item(0)->childNodes->item(0)->getAttribute('src');
?>

$ret is the HTML text source
this code is shown how to converting HTML to XML using PHP DOMdocument class.

2 comments:

Anonymous said...

not working...

andrea chiu said...

Just stopping by to see something to read and luckily I found it here what I am looking for. Have a great day! Try visiting my site. Thank you.
nhella

www.triciajoy.com

Post a Comment