aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/Esc.php
blob: eaefc10d3d9eca8bad460cb933f53612bbe3e03d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php


namespace r7r\cms\sys;

class Esc
{
    public const HTML = 1;
    public const NL2BR = 2;
    public const HTML_WITH_BR = self::HTML | self::NL2BR;

    public static function esc(string $s, int $flags = self::HTML): string
    {
        if ($flags & self::HTML) {
            $s = htmlspecialchars($s, ENT_QUOTES, "UTF-8");
        }
        if ($flags & self::NL2BR) {
            $s = nl2br($s);
        }
        return $s;
    }
}