Guest User

Untitled

a guest
May 7th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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. )
Advertisement
Add Comment
Please, Sign In to add comment