|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-09-07 14:24 UTC] cmb@php.net
-Summary: DOMXpath adds to string
+Summary: DOM::loadHTML() --> ::saveXML() entity encodes CR
[2015-09-07 14:24 UTC] cmb@php.net
[2021-03-12 18:51 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-03-12 18:51 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 09:00:01 2025 UTC |
Description: ------------ The output shows an entity for every line break in $contents var. I am using PHP 5.5.8 build date Jan 8 2014 15:26:26 Test script: --------------- <?php $contents = '<!DOCTYPE html> <html lang="pt"><head><meta charset="utf-8"></head> <body> <div class="div_entry"> <div class="div_imagem"> <a href="test.html"> <img src="test.png" alt="" />Link to imagem</a> </div> <div class="div_product">This is a title for a product</div> <div class="div_price">R$50,00</div> </div>'; $doc = new DOMDocument(); $doc->loadHTML('<?xml encoding="UTF-8">' . $contents); $xpath = new DOMXpath($doc); $xquery = '//div[@class="div_entry"]'; $articles = $xpath->query($xquery); $registros = array(); foreach ($articles as $i => $article) { $registros[] = $article->ownerDocument->saveXML($article); } // end foreach echo "<pre>"; print_r($registros); echo "</pre>"; ?>