Decoding HTML Entities to a String

Problem

You have a string encoded by HTML::entities() and want to decode it back to the original string.

Solution

Use the HTML::decode() method.

This is the opposite of HTML::entities(). For example.

$string HTML::decode('<h1>Hello</h1>');

In this example $string will equal <h1>Hello</h1>;

Discussion

This method wraps the PHP html_entity_decode() function.

Specifically it calls html_entity_decode($value, ENT_QUOTES, 'UTF-8'). These options compliment the ones passed to htmlentities() by the HTML::entities() method.



from Linux Hint https://ift.tt/3kFasvt

Post a Comment

0 Comments