Khanh Tran
Khanh Tran

Reputation: 1826

Decode JavaScript encoded content

I'm writing a web crawler tool to collect the email addresses. After downloading the HTML content and parsing it using DomCrawler, I get this node value:

<!--
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.

How could I decode it?

Upvotes: 1

Views: 78

Answers (1)

Alexander Higgins
Alexander Higgins

Reputation: 6923

The value is just html encoded values of the characters from the original string so in PHP you can use html_entity_decode to get the original text.

$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);

See: https://www.functions-online.com/html_entity_decode.html

Upvotes: 2

Related Questions