php對表單內容進行處理
/**
* 過濾HTML內容後返回
*
* @param $string
* @param bool $html
*
* @return array|string
*/
public static function safeOutput($string, $html = false) {
if (!$html)
$string = strip_tags($string);
return @Tools::htmlentitiesUTF8($string, ENT_QUOTES);
}
public static function htmlentitiesUTF8($string, $type = ENT_QUOTES) {
if (is_array($string))
return array_map(array('Tools', 'htmlentitiesUTF8'), $string);
return htmlentities((string)$string, $type, 'utf-8');
}
public static function htmlentitiesDecodeUTF8($string) {
if (is_array($string))
return array_map(array('Tools', 'htmlentitiesDecodeUTF8'), $string);
return html_entity_decode((string)$string, ENT_QUOTES, 'utf-8');
}
/**
* 對POST內容進行處理
*
* @return array
*/
public static function safePostVars() {
if (!is_array($_POST))
return array();
$_POST = array_map(array('Tools', 'htmlentitiesUTF8'), $_POST);
}