Among the string operation functions, string case conversion is also a relatively commonly used function, and its underlying implementation is also It’s relatively simple, let’s find out below.
I have more detailed annotations on the PHP source code on github. If you are interested, you can take a look and give it a star. PHP5.4 source code annotations. You can view the added annotations through the commit record.
<p>string strtolower ( string $string )</p>
Convert the string to lowercase characters.
<p>string strtoupper ( string $string )</p>
Convert the string to uppercase characters.
<span>$str</span> = 'Hello World'<span>; </span><span>$new_str</span> = <span>strtolower</span>(<span>$str</span>); <span>//</span><span> hello world</span> <span>$str</span> = 'hello world'<span>; </span><span>$new_str</span> = strupper(<span>$str</span>); <span>//</span><span> HELLO WORLD</span>
<p>拷贝一份字符串</p> <p>php_strtolower/php_strtoupper进行转换</p>
The core operations of the two functions are similar. Let’s talk about strtolower, the other one is similar.
The core code of the php_strtolower function is as follows:
c = (unsigned <span>char</span> *<span>)s; e </span>= c+<span>len; </span><span>//</span><span> 遍历s,逐个变为小写</span> <span>while</span> (c <<span> e) { </span>*c = tolower(*<span>c); c</span>++<span>; } </span><span>return</span> s;
This function traverses the entire string and converts it into lowercase characters one by one. This is also a classic pointer operation.
Original article with limited writing style and limited knowledge. If there is anything wrong in the article, please let me know.
If this article is helpful to you, please click to recommend it, thank you^_^
Finally, I have more detailed annotations on the PHP source code on github. If you are interested, you can take a look and give it a star. PHP5.4 source code annotations. You can view the added annotations through the commit record.
For more source code articles, please visit your personal homepage to continue viewing: hoohack