Name

html_entities()

Synopsis

    string html_entities ( string html [, int options [, string charset]] )

The html_entities() function converts characters that are illegal in HTML, such as &, <, and ", into their safe equivalents: &amp;, &lt;, and &quot;, respectively.

    $flowerpot_men = "Bill & Ben";
    $safe_flowerpots = htmlentities($flowerpot_men);
    // it's now "Bill &amp; Ben"

This method of encoding is often referred to as &-escaping. You can reverse this conversion using the html_entity_decode() function.

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.