Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: extra content at the end of the document in entity, trying to extract the nodeValue

<?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
like image 206
KJW Avatar asked Oct 09 '12 18:10

KJW


1 Answers

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>
like image 92
kirugan Avatar answered Sep 21 '22 19:09

kirugan