怎样成PHP高手?学会懒惰的去编程

来源:eNet硅谷动力 作者:PHPChina 梓萱 2007-12-03 出处:pcdog.com

.net  dos  linux  mysql  数据库  
上一页 1 2 3 4 5 6 7 8 9 10 11 下一页 

  测试str_replace和ereg_replace的运行速度


  //这段代码测试str_replace的运行速度

  emphasis; ?>


  for ($i=0; $i<1000; $i++) {

  str_replace(i>, b>, $string).

  ;

  }

  ?>


  //这段代码测试ereg_replace的运行速度


  for ($i=0; $i<1000; $i++) {

  ereg_replace(<([/]*)i>, <\1b>, $string).

  ;

  }

  ?>


  //打印结果


  结论


  使用str_replace的时间 -

  使用ereg_pattern的时间 -

  运行上面的代码,得到的结果是:

  使用str_replace的时间 - 0.089757

  使用ereg_pattern的时间 - 0.248881

  从运行的结果我们可以看出使用str_replace替代ereg_replace作为字符串替换函数,极大地提高了代码的运行速度。
更多内容请看PCdog.com--PHP技巧篇专题
上一页 1 2 3 4 5 6 7 8 9 10 11 下一页 
上一篇:PHP编程中八种常见的文件操作方式
下一篇:入门:PHP编程中“字符串”小常识