Files
2026-07-01 16:44:17 +03:00

56 lines
1.3 KiB
PHP

<?php namespace ZN\Security;
/**
* ZN PHP Web Framework
*
* "Simplicity is the ultimate sophistication." ~ Da Vinci
*
* @package ZN
* @license MIT [http://opensource.org/licenses/MIT]
* @author Ozan UYKUN [ozan@znframework.com]
*/
use ZN\Helper;
class Html
{
/**
* Encode HTML
*
* @param string $string
* @param string $type = 'quotes'
* @param string $encoding = 'utf-8'
*
* @return string
*/
public static function encode(string $string, string $type = 'quotes', string $encoding = 'utf-8') : string
{
return str_replace('&amp;', '&', htmlspecialchars(trim($string), Helper::toConstant($type, 'ENT_'), $encoding, false));
}
/**
* Decode HTML
*
* @param string $string
* @param string $type = 'quotes'
*
* @return string
*/
public static function decode(string $string, string $type = 'quotes') : string
{
return htmlspecialchars_decode(trim($string), Helper::toConstant($type, 'ENT_'));
}
/**
* Clean HTML Tag
*
* @param string $string
* @param mixed $allowable = ''
*
* @return string
*/
public static function tagClean(string $string, $allowable = '') : string
{
return strip_tags(self::decode($string), $allowable);
}
}