PHP源码阅读笔记:nl2br, ltrim, rtrim, trim函数string nl2br ( string string )Returns string with ‘‘ inserted before all newlines.在代码中有注释如下:/* it is really faster to scan twice and allocate mem once insted scanning onceand constantly reallocing */程序先计算需要替换的个数,然后一次性计算需要分配的内存大小。从而减少了每次替换都重新分配内存的开销。由此可见PHP源码的作者的程序优化上下了不少功夫。源码摘抄如下:1
2
3
4
5
6
7
8
9
10
11
12
13