Seven: String interception function: str_replace(find,replace,string,count);
substr_replace(string,replace,start,length);
<code><span>$msg</span> = <span>"hello,word I love php"</span>; <span>$rs</span> = substr_replace(<span>$msg</span>,<span>"mysql"</span>,-<span>3</span>,<span>3</span>); <span>echo</span><span>$rs</span>.<span>"<br/>"</span>; <span>$rsl</span> = str_replace(<span>"word"</span>, <span>"php"</span>, <span>$msg</span>); <span>echo</span><span>$rsl</span>;</code>
As shown in the figure below, substr_replace(string,replace,start,length) ; Mainly for replacement of positions in strings. string is
The searched string, replace is the character to be replaced, start is the starting position of replacement (if it is a positive number, search from the left. If it is a negative number, search from the right), length (optional. If not selected, then Indicates replacing all characters after the starting position) indicates the length to be replaced.
str_replace(find,replace,string,count); find represents the character to be replaced. replace represents the character to be replaced. string represents the string to be found. count represents the number of executions (optional). This function is case sensitive. Case-insensitive str_ireplace(); usage is the same as str_replace().
<code><span>$msg1</span> = <span>"hello"</span>;
<span>$msg2</span> = <span>"HELLO"</span>;
<span>echo</span> strcmp(<span>$msg1</span>, <span>$msg2</span>).<span>"<br/>"</span>;
<span>echo</span> strcasecmp(<span>$msg1</span> ,<span>$msg2</span>);</code>
<code><span>$str</span> = <span>"I AM PETAL"</span>;
<span>echo</span> strtolower(<span>$str</span>).<span>"<br/>"</span>; <span>//大写转换为小写</span><span>$stra</span> = <span>"i am petal"</span>;
<span>echo</span> strtoupper(<span>$stra</span>).<span>"<br/>"</span>; <span>// 小卫转换为大写</span><span>echo</span> ucfirst(<span>$stra</span>).<span>"<br/>"</span>; <span>//只将字符串的第一个字符转换为大写</span><span>echo</span> ucwords(<span>$stra</span>); <span>//将字符串每一个单词的首字母转换为大写</span></code>