<?php
echo getValue('<a>dk</a><b>sh</b>', 'a');
function getValue($string, $tagname) {
$dom = new DomDocument();
$dom->loadXML($string);
$node_list = $dom->getElementsByTagName($tagname)->item(0);
return $node_list->nodeValue;
}
running the script returns
Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in /Users/johnkim/get.php on line 7
Well, your xml string is not valid. Try to wrap it with any tag like:
<some_tag><a>sdfsdf</a><b>sdfsdf</b></some_tag>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With