Bug #70450 [Opn]: DOM::loadHTML() --> ::saveXML() entity encodes CR
| From: | cmb@php.net | Date: | Mon, 07 Sep 2015 14:24:59 +0000 |
| Subject: | Bug #70450 [Opn]: DOM::loadHTML() --> ::saveXML() entity encodes CR | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-195849@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70450&edit=1
ID: 70450
Updated by: cmb@php.net
Reported by: flavio dot cambraia at yahoo dot com dot br
-Summary: DOMXpath adds to string
+Summary: DOM::loadHTML() --> ::saveXML() entity encodes CR
Status: Open
Type: Bug
Package: DOM XML related
Operating System: Windows
PHP Version: 5.5.29
Block user comment: N
Private report: N
New Comment:
This has nothing to do with XPath. Rewriting the code to use
"classic" DOM methods yields the same result.
Previous Comments:
------------------------------------------------------------------------
[2015-09-07 14:00:02] flavio dot cambraia at yahoo dot com dot br
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>";
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70450&edit=1