Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP. XPath. Call to str_replace() cause an 'unterminated entity' error.
- $html = '<a href="/browse/product.do?cid=1&vid=1&pid=1" class="productItemName">what is going on here</a>';
- $dom = new DOMDocument();
- $dom->loadhtml($html);
- $xpath = new DOMXPath($dom);
- $selectors['link'] = '//a/@href';
- $links_nodeList = $xpath->query($selectors['link']);
- foreach ($links_nodeList as $link) {
- $link->nodeValue = str_replace("http://www.test.com",'',$link->nodeValue); // relativize link
- $links[] = $link->nodeValue;
- }
- echo("<p>links</p>");
- echo("<pre>");
- print_r($links);
- echo("</pre>");
- Warning: main() [function.main]: unterminated entity reference vid=1&pid=1 in C:Usersdirpublic_htmlwhatisgoingon.php on line 14
- links
- Array
- (
- [0] => /browse/product.do?cid=1
- )
- $link->nodeValue = str_replace("http://www.test.com",'',$link->nodeValue);
- foreach ($links_nodeList as $link) {
- $link->nodeValue = str_replace("http://www.test.com",'',htmlspecialchars($link->nodeValue)); // relativize link
- $links[] = htmlspecialchars($link->nodeValue, ENT_QUOTES, 'UTF-8');
- }
- Array
- (
- [0] => /browse/product.do?cid=1&vid=1&pid=1
- )
Advertisement
Add Comment
Please, Sign In to add comment