测试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技巧篇专题
