2012-10-09 11 views
8
<?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; 
} 

in esecuzione lo script restituiscePHP: contenuti extra alla fine del documento in entità, cercando di estrarre il nodeValue

Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in /Users/johnkim/get.php on line 7 

risposta

13

Bene la stringa XML non è valido. Prova a racchiuderlo con qualsiasi tag come:

<some_tag><a>sdfsdf</a><b>sdfsdf</b></some_tag> 
Problemi correlati