Skip to content

Escaper

Zemit\Html\Escaper

Escapes different kinds of text securing them. By using this component you may prevent XSS attacks.

This component only works with UTF-8. The PREG extension needs to be compiled with UTF-8 support.

$escaper = new \Phalcon\Html\Escaper();

$escaped = $escaper->escapeCss("font-family: <Verdana>");

echo $escaped; // font\2D family\3A \20 \3C Verdana\3E

Methods

json

Escapes a JSON string by raw URL encoding it.

public json(mixed|null $json = null): string

JS side could decode and parse this way: JSON.parse(decodeURIComponent('<?= $this->escaper->json([]);?>'));

Parameters:

Parameter Type Description
$json **mixed null**

Return Value:

Returns the raw URL encoded JSON string.