php

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.

About the author

laravelrecipies