aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/Esc.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-09-25 21:24:01 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-09-25 21:27:43 +0200
commit78c0350b3b7fc025ba565e19bfa195b68e95bb88 (patch)
tree94ac3aba1cba328a7e50bac408e72c269d18d9b4 /ratatoeskr/sys/Esc.php
parent60542d424f71347e75e3e43daf964f679cf26aee (diff)
downloadratatoeskr-cms-78c0350b3b7fc025ba565e19bfa195b68e95bb88.tar.gz
ratatoeskr-cms-78c0350b3b7fc025ba565e19bfa195b68e95bb88.tar.bz2
ratatoeskr-cms-78c0350b3b7fc025ba565e19bfa195b68e95bb88.zip
Deprecate htmlesc for Esc::esc
"Stole" this class from another project of mine (micropoly)
Diffstat (limited to 'ratatoeskr/sys/Esc.php')
-rw-r--r--ratatoeskr/sys/Esc.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/ratatoeskr/sys/Esc.php b/ratatoeskr/sys/Esc.php
new file mode 100644
index 0000000..eaefc10
--- /dev/null
+++ b/ratatoeskr/sys/Esc.php
@@ -0,0 +1,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;
+ }
+}