fork(3) download
  1. <?php
  2. outputImages();
  3. outputSpans();
  4.  
  5.  
  6.  
  7.  
  8. function outputImages(){
  9. $html = "<div class='test'>
  10. <pre>
  11. <img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
  12. <img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
  13. <img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
  14. </pre>
  15. </div>";
  16. getHtml($html);
  17. }
  18.  
  19.  
  20. function outputSpans(){
  21. $html = "<div class='test'>
  22. <pre>
  23. <span>a</span>
  24. <span>b</span>
  25. <span>c</span>
  26. </pre>
  27. </div>";
  28. getHtml($html);
  29. }
  30.  
  31.  
  32. function getHtml($html){
  33. $doc = new DOMDocument;
  34. $doc->loadhtml($html);
  35. $xpath = new DOMXPath($doc);
  36. $tags = $xpath->query('//div[@class="test"]');
  37. print(get_inner_html($tags[0]));
  38. }
  39.  
  40.  
  41. function get_inner_html( $node ) {
  42. $innerHTML= '';
  43. $children = $node->childNodes;
  44. foreach ($children as $child) {
  45. $innerHTML .= $child->ownerDocument->saveXML( $child );
  46. }
  47.  
  48. return $innerHTML;
  49. }
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
					<pre>
					<img src="http://d...content-available-to-author-only...e.com/5x5/000/fff"/><img src="http://d...content-available-to-author-only...e.com/5x5/000/fff"/><img src="http://d...content-available-to-author-only...e.com/5x5/000/fff"/></pre>
				
					<pre>
					<span>a</span>
					<span>b</span>
					<span>c</span>
					</pre>