Function Time (s) Memory (b)
32Kb File 1Mb File 32Kb File 1Mb File
file_get_contents 0.00152 0.00564 52480 1067856
fgets 0.00195 0.07190 30760 30768
file 0.00157 0.06464 87344 2185624
require_once 0.00225 0.08065 67992 2067696
include 0.00222 0.08202 67928 2067624
readfile 0.00117 0.00191 19192 19208
fpassthru 0.00117 0.00184 20016 20032
readfile and fpassthru have once again tied for first place.
This new set of results just confirms the fact that speed and scalability comes from your design and not from your code.
The difference between the best performance and the worst is just 0.00108s too close to call.
PHP 中文分词 , php5 支持 模式修饰符u ,
$str = "hi钓鱼岛是中国的";
preg_match_all("/./u", $str, $arr);
print_r($arr[0]);
PHP分割中文字符串
$str = "爱莲说";
preg_match_all('/[\x{4e00}-\x{9fa5}]/u',$str,$arr);
dump($arr);
//////
还有就是专业的SCWS 中文分词 SCWS 是 Simple Chinese Word Segmentation,基于词频词典的机械式中文分词引擎,将一整段的中文正确地切分成词,纯C语言开发,不依赖外部库函数,用动态链接库嵌入应用程序,支持GBK、UTF-8 等, PHP 扩展模块在PHP中用分词 能满足一些小型搜索引擎 关键字提取等场合运用 //github.com/hightman/scws
PHP trim 函数不能处理 半角空格
php默认不能正确处理多字节字符,比如中文,如果要处理中文,
要用mb_开头的函数,参考:http://php.net/manual/zh/ref.mbstring.php
官方给的例子
function mb_trim($string, $trim_chars = '\s'){
return preg_replace('/^['.$trim_chars.']*(?U)(.*)['.$trim_chars.']*$/u', '\\1',$string);
}网友写的
function mb_trim($string){ // u模式符表示 字符串被当成 UTF-8处理
return preg_replace('/(^\s+)|(\s+$)/u', '', $string);
}
encoding 可选 字符编码 可以是utf-8 或 ucs2 或 gb2312 等
关闭nginx版本号在conf/nginx.conf http 段增加 server_tokens off;
关闭PHP版本号在etc/php.ini 搜索 expose_php 改为 Off是否暴露 PHP 被安装在服务器上如在 Web 服务器的信息头中加上其签名:X-Powered-By: PHP/7.0.17
感谢您的支持,我会继续努力的!
支付宝扫一扫,即可进行扫码打赏哦
2692PHP file_get_contents,fpassthru,fgets,file,require_once,include,readfile效率
Function Time (s) Memory (b)
32Kb File 1Mb File 32Kb File 1Mb File
file_get_contents 0.00152 0.00564 52480 1067856
fgets 0.00195 0.07190 30760 30768
file 0.00157 0.06464 87344 2185624
require_once 0.00225 0.08065 67992 2067696
include 0.00222 0.08202 67928 2067624
readfile 0.00117 0.00191 19192 19208
fpassthru 0.00117 0.00184 20016 20032
readfile and fpassthru have once again tied for first place.
This new set of results just confirms the fact that speed and scalability comes from your design and not from your code.
The difference between the best performance and the worst is just 0.00108s too close to call.
2687PHP中文分词
PHP 中文分词 , php5 支持 模式修饰符u ,
$str = "hi钓鱼岛是中国的";
preg_match_all("/./u", $str, $arr);
print_r($arr[0]);
PHP分割中文字符串
$str = "爱莲说";
preg_match_all('/[\x{4e00}-\x{9fa5}]/u',$str,$arr);
dump($arr);
//////
还有就是专业的SCWS 中文分词 SCWS 是 Simple Chinese Word Segmentation,基于词频词典的机械式中文分词引擎,将一整段的中文正确地切分成词,纯C语言开发,不依赖外部库函数,用动态链接库嵌入应用程序,支持GBK、UTF-8 等, PHP 扩展模块在PHP中用分词 能满足一些小型搜索引擎 关键字提取等场合运用 //github.com/hightman/scws
2686PHP trim 函数不能删除半角空格的问题
PHP trim 函数不能处理 半角空格
php默认不能正确处理多字节字符,比如中文,如果要处理中文,
要用mb_开头的函数,参考:http://php.net/manual/zh/ref.mbstring.php
官方给的例子
function mb_trim($string, $trim_chars = '\s'){
return preg_replace('/^['.$trim_chars.']*(?U)(.*)['.$trim_chars.']*$/u', '\\1',$string);
}
网友写的
function mb_trim($string){ // u模式符表示 字符串被当成 UTF-8处理
return preg_replace('/(^\s+)|(\s+$)/u', '', $string);
}
2676PHP mb_substr() 函数 字符编码
encoding 可选 字符编码 可以是utf-8 或 ucs2 或 gb2312 等
2668PHP 安装
关闭nginx版本号
在conf/nginx.conf http 段增加 server_tokens off;
关闭PHP版本号
在etc/php.ini 搜索 expose_php 改为 Off
是否暴露 PHP 被安装在服务器上
如在 Web 服务器的信息头中加上其签名:X-Powered-By: PHP/7.0.17