时间:2021-07-01 10:21:17 帮助过:4人阅读
程序一,PHP substr
- php
- function getmicrotime(){
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- $time_start = getmicrotime();
- $abc="重庆,万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,
大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,";- $l=strlen($abc);
- $abc=substr($abc,0,$l-1);
- echo $abc."<br>";
- $time_end = getmicrotime();
- echo ($time_end-$time_start)*1000;
- ?>
程序二,利用正则表达式
- php
- function getmicrotime(){
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
- $time_start = getmicrotime();
- $abc="重庆,万州,涪陵,渝中,大渡口,江北,沙坪坝,九龙坡,南岸,北碚,万盛,双挢,渝北,巴南,黔江,长寿,綦江,潼南,铜梁,
大足,荣昌,壁山,梁平,城口,丰都,垫江,武隆,忠县,开县,云阳,奉节,巫山,巫溪,石柱,";- $abc=str_replace(",$","",$abc);
- echo $abc."<br>";
- $time_end = getmicrotime();
- echo ($time_end-$time_start)*1000;
- ?>
http://www.bkjia.com/PHPjc/446480.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446480.htmlTechArticlePHP是我们现在最常用的动态开发WEB页面的语言,字符串的处理在编程中是最长用到的,我们这里就详细的谈谈PHP substr的利用。有一堆类似以...