javascript - 解码 JavaScript 编码的内容

标签 javascript php

我正在编写一个网络爬虫工具来收集电子邮件地址。下载 HTML 内容并使用 DomCrawler 解析后,我得到了这个节点值:

<!--
document.write("<a rel='nofollow' href='mailto:&#104;&#105;&#101;&#117;&#98;&#100;&#115;&#104;&#97;&#112;&#112;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;'>&#104;&#105;&#101;&#117;&#98;&#100;&#115;&#104;&#97;&#112;&#112;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;");
//-->This email address has been protected. You need to enable JavaScript to view the content.

我如何解码它?

最佳答案

该值只是原始字符串中字符的 html 编码值,因此在 PHP 中您可以使用 html_entity_decode 获取原始文本。

$returnValue = html_entity_decode('mailto:&#104;&#105;&#101;&#117;&#98;&#100;&#115;&#104;&#97;&#112;&#112;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;'>&#104;&#105;&#101;&#117;&#98;&#100;&#115;&#104;&#97;&#112;&#112;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;', ENT_COMPAT);

参见:https://www.functions-online.com/html_entity_decode.html

关于javascript - 解码 JavaScript 编码的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45125266/

相关文章:

javascript - webpack2 使用 knockout 模板进行 tree-shaking

javascript - JavaScript 中的 Switch 语句

javascript - 康瓦 : get corners coordinate of a rotated rectangle

php - 在 XAMPP 1.8.3 Windows 7 安装上升级 PHP

javascript - 如何使用 jQuery 同时在多个元素上更改不同的 css 属性

javascript - 获取触发事件的元素的 ID

javascript - php header 位置未重定向,也没有错误

php - 如果日期等于用户的生日,如何向用户回显?

php preg_match 在 C++ 中与 Boost 的等价物?

php - 将一个父级和多个相同的子级转换为 xml