1. 方法:
function new_stripslashes($string)
{
if (!is_array($string)) {
return stripslashes($string);
}
foreach ($string as $key => $val) {
$string[$key] = new_stripslashes($val);
}
return $string;
}
function string2array($data)
{
if ($data == '') {
return array();
}
@eval("\$array = $data;");
return $array;
}
function exit_msg($msg = '', $title = '提示')
{
$msg = nl2br($msg);
$str = <<<str
<!DOCTYPE html><html><head><meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'/>
<title>{$title}</title>
<style type="text/css">
body{background:#fff;font-family: 'Microsoft YaHei'; color: #333;}
.info{width:90%;font-size:100%; line-height:150%; margin:20px auto; padding:10px;border:solid 1px #ccc;}
</style>
</head>
<body>
<div class="info">{$msg}</div>
</body>
</html>
str;
echo $str;
exit();
}
/**
* 功能:计算文件大小
* @param int $bytes
* @return string 转换后的字符串
*/
function get_byte($bytes)
{
if (empty($bytes)) {
return '--';
}
$sizetext = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), 2) . $sizetext[$i];
}
/**
* 获取文件目录列表
* @param string $pathname 路径
* @param integer $fileFlag 文件列表 0所有文件列表,1只读文件夹,2是只读文件(不包含文件夹)
* @param string $pathname 路径
* @return array
*/
function get_file_folder_List($pathname, $fileFlag = 0, $pattern = '*')
{
$fileArray = array();
$pathname = rtrim($pathname, '/') . '/';
$list = glob($pathname . $pattern);
foreach ($list as $i => $file) {
switch ($fileFlag) {
case 0:
$fileArray[] = basename($file);
break;
case 1:
if (is_dir($file)) {
$fileArray[] = basename($file);
}
break;
case 2:
if (is_file($file)) {
$fileArray[] = basename($file);
}
break;
default:
break;
}
}
if (empty($fileArray)) {
$fileArray = null;
}
return $fileArray;
}
2. static 局部变量 作用,以及 swoole ,workman 。