$sanitizer->entities() method

Entity encode a string for output

Wrapper for PHP's htmlentities() function that contains typical ProcessWire usage defaults

The arguments used here are identical to those for PHP's htmlentities function, except that the ProcessWire defaults for encoding quotes and using UTF-8 are already populated.


$test = "ain't <em>nothing</em> perfect but our brokenness";
echo $sanitizer->entities($test);
// result: ain&apos;t &lt;em&gt;nothing&lt;/em&gt; perfect but our brokenness


// basic usage
$string = $sanitizer->entities(string $str);

// usage with all arguments
$string = $sanitizer->entities(string $str, $flags = 3, string $encoding = 'UTF-8', bool $doubleEncode = true);



String to entity encode

flags (optional)int, bool

See PHP htmlentities() function for flags.

encoding (optional)string

Encoding of string (default="UTF-8").

doubleEncode (optional)bool

Allow double encode? (default=true).

Return value


Entity encoded string

See Also

$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.209

Twitter updates

  • Adding custom actions to ProcessWire image fields in the admin, part of this week’s dev branch additions: More
    27 January 2023
  • ProcessWire 3.0.210 new main/master version released— More
    6 January 2023
  • ProcessWire 3.0.209: Core updates and an interesting AI that knows ProcessWire– More
    30 December 2022

Latest news

  • ProcessWire Weekly #455
    In the 455th issue of ProcessWire Weekly we'll check out the latest core updates, introduce a new third party module called JkPublishPages, and more. Read on!
    Weekly.pw / 28 January 2023
  • ProcessWire 3.0.210 new main/master version
    140 commits, 55 resolved issues, dozens of new features, eight contributors, and five new pull requests make yet another great new version of ProcessWire.
    Blog / 6 January 2023
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer