How to workaround PHP advanced html dom's conversion of entities?

荒凉一梦 提交于 2019-12-12 04:39:20

问题


How can I workaround advanced_html_dom.php str_get_html's conversion of HTML entities, short of applying htmlentities() on every element content?

Despite

http://archive.is/YWKYp#selection-971.0-979.95

The goal of this project is to be a DOM-based drop-in replacement for PHP's simple html dom library.

... If you use file/str_get_html then you don't need to change anything.

I find on

include 'simple_html_dom.php';
$set = str_get_html('<html><title>&nbsp;</title></html>');
echo ($set->find('title',0)->innertext)."\n";  // Expected: &nbsp;  Observed: &nbsp;

changing to advanced HTML DOM gives an incompatible result:

include 'advanced_html_dom.php';
$set = str_get_html('<html><title>&nbsp;</title></html>');
echo ($set->find('title',0)->innertext)."\n";    // Expected: &nbsp;  Observed: -á

This issue is not confined to spaces.

$set = str_get_html('<html><body>&bull;</body></html>'); 
echo $set->find('body',0)->innertext; // Expected $bull; Observed ÔÇó

回答1:


You can check my own package PHPHTMLQuery, it helps you to use PHP to select HTML element using most of CSS3 selectors.

the package works with external links and internal html files too.

Installation

Open your terminal and browse into your project root folder and run

composer require "abdelilahlbardi/phphtmlquery":"@dev"

Documentation

For more informations, please visit the package link: PHPHTMLQuery



来源:https://stackoverflow.com/questions/35277100/how-to-workaround-php-advanced-html-doms-conversion-of-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!