/**
* html轉換輸出(只轉義
* @param $param
* @return string
*/
function htmlEscape($param) {
return trim(htmlspecialchars($param
}
/**
* 是否數組(同時檢測數組中是否存在值)
* @param $params
* @return boolean
*/
function isArray($params) {
return (!is_array($params) || !count($params)) ? false : true;
}
/**
* 變量是否在數組中存在(參數容錯
* @param $param
* @param $params
* @return boolean
*/
function inArray($param
return (!in_array((string)$param
}
/**
* 通用多類型混合轉義函數
* @param $var
* @param $strip
* @param $isArray
* @return mixture
*/
function sqlEscape($var
if (is_array($var)) {
if (!$isArray) return "
foreach ($var as $key => $value) {
$var[$key] = trim(S::sqlEscape($value
}
return $var;
} elseif (is_numeric($var)) {
return "
} else {
return "
}
}
/**
* 獲取服務器變量
* @param $keys
* @return string
*/
function getServer($keys) {
$server = array();
$array = (array) $keys;
foreach ($array as $key) {
$server[$key] = NULL;
if (isset($_SERVER[$key])) {
$server[$key] = str_replace(array(
}
}
return is_array($keys) ? $server : $server[$keys];
}
/**
* 變量轉義
* @param $array
*/
function slashes(&$array) {
if (is_array($array)) {
foreach ($array as $key => $value) {
if (is_array($value)) {
S::slashes($array[$key]);
} else {
$array[$key] = addslashes($value);
}
}
}
}
/**
* 目錄轉換
* @param unknown_type $dir
* @return string
*/
function escapeDir($dir) {
$dir = str_replace(array("
return rtrim(preg_replace(
}
/**
* 通用多類型轉換
* @param $mixed
* @param $isint
* @param $istrim
* @return mixture
*/
function escapeChar($mixed
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = S::escapeChar($value
}
} elseif ($isint) {
$mixed = (int) $mixed;
} elseif (!is_numeric($mixed) && ($istrim ? $mixed = trim($mixed) : $mixed) && $mixed) {
$mixed = S::escapeStr($mixed);
}
return $mixed;
}
/**
* 字符轉換
* @param $string
* @return string
*/
function escapeStr($string) {
$string = str_replace(array(""
$string = preg_replace(array(
$string = str_replace(array("%
$string = str_replace(array("%
$string = str_replace(array(
return $string;
}
/**
* 變量檢查
* @param $var
*/
function checkVar(&$var) {
if (is_array($var)) {
foreach ($var as $key => $value) {
S::checkVar($var[$key]);
}
} elseif (P_W !=
$var = str_replace(array(
} elseif (str_replace(array(
global $basename;
$basename =
adminmsg(
}
}
From:http://tw.wingwit.com/Article/program/PHP/201311/21225.html