daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Jan 12th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Retriving content of the elements in a XML string
  2. $xml = '<element_1>foobar</element_1>';
  3.  
  4. $dd = new DOMDocument();
  5. $dd->loadXml($xml);
  6.  
  7. var_dump($dd->getElementsByTagName('element_1')); //this prints object(DOMNodeList)#2 (0) {
  8. }
  9.    
  10. $xml = '<element_1>foobar</element_1>';
  11.  
  12. $dd = new DOMDocument();
  13. $dd->loadXml($xml);
  14.  
  15. var_dump($dd->getElementsByTagName('element_1')->item(0)->nodeValue);
  16. //string 'foobar' (length=6)
  17.    
  18. <?php
  19.  
  20. $xml = <<<XML
  21. <?xml version='1.0'?>
  22. <element_1>
  23. foobar
  24. </element_1>
  25. XML;
  26.  
  27. $data = simplexml_load_string($xml);
  28.  
  29. echo $data;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top