Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.12 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP. XPath. Call to str_replace() cause an 'unterminated entity' error.
  2. $html = '<a href="/browse/product.do?cid=1&vid=1&pid=1" class="productItemName">what is going on here</a>';
  3.  
  4. $dom = new DOMDocument();
  5. $dom->loadhtml($html);
  6. $xpath = new DOMXPath($dom);
  7.  
  8. $selectors['link'] = '//a/@href';
  9. $links_nodeList = $xpath->query($selectors['link']);
  10.  
  11. foreach ($links_nodeList as $link) {
  12.     $link->nodeValue = str_replace("http://www.test.com",'',$link->nodeValue); // relativize link
  13.     $links[] = $link->nodeValue;
  14. }
  15.  
  16. echo("<p>links</p>");
  17. echo("<pre>");
  18. print_r($links);
  19. echo("</pre>");
  20.        
  21. Warning: main() [function.main]: unterminated entity reference vid=1&pid=1 in C:Usersdirpublic_htmlwhatisgoingon.php on line 14
  22. links
  23.  
  24. Array
  25. (
  26.     [0] => /browse/product.do?cid=1
  27. )
  28.        
  29. $link->nodeValue = str_replace("http://www.test.com",'',$link->nodeValue);
  30.        
  31. foreach ($links_nodeList as $link) {
  32.     $link->nodeValue = str_replace("http://www.test.com",'',htmlspecialchars($link->nodeValue)); // relativize link
  33.     $links[] = htmlspecialchars($link->nodeValue, ENT_QUOTES, 'UTF-8');
  34. }
  35.        
  36. Array
  37. (
  38.     [0] => /browse/product.do?cid=1&vid=1&pid=1
  39. )