标题:php code snippit 出处:Felix021 时间:Thu, 29 Oct 2015 10:51:23 +0000 作者:felix021 地址:https://www.felix021.com/blog/read.php?2148 内容: 转置二维数组:function transpose($array) { array_unshift($array, null); return call_user_func_array('array_map', $array); } utf-8字符串转为utf-8字符数组:function utf8_str2arr($str) { preg_match_all("/./u", $str, $arr); return $arr[0]; } 按显示宽度截取utf-8字符串function substr_width($str, $start, $width) { $arr = utf8_str2arr($str); $arr_ret = []; $i = 0; while ($width > 0 and $i < count($arr)) { $arr_ret[] = $arr[$start + $i]; if (strlen($arr_ret[$i]) == 1) //ascii,width=1 $width -= 1; else $width -= 2; $i++; } if ($width < 0) array_pop($arr_ret); return join('', $arr_ret); } 让进程在后台运行(detached process),出乎意料地简单 pclose(popen("nohup $cmd &", 'r')); Generated by Bo-blog 2.1.0