Seven: string intercept function: Str_replace (find,replace,string,count);
Substr_replace (string,replace,start,length);
$msg"hello,word I love php";$rs = substr_replace($msg,"mysql",-3,3);echo$rs."
";$rsl = str_replace("word""php"$msg);echo$rsl;
As shown, Substr_replace (string,replace,start,length), mainly for the position of the string in the substitution. string is
The string to be searched for, replace is the character to be replaced, and start is the position at which to start the substitution (if positive, find from left.) As negative, from right to start), length (optional). If not selected, replaces all characters after the start position to indicate 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. A string that represents the strings to find. Count indicates the number of executions (optional). This function is case sensitive. Str_ireplace () is not sensitive to case, and the usage and str_replace () are the same.
Eight: Compare String function strcmp ( stR1, str2). STRCASECMP (STR1,STR2);
$msg1"hello"; $msg2"HELLO"; echo strcmp($msg1$msg2)."
"; echo strcasecmp($msg1 ,$msg2);
The results are as follows. The difference between the two functions is that strcmp () is lowercase sensitive, and strcasecmp () is not case sensitive.
When comparing the character typeface, the return value is 0. When str1 > str2, the return value is greater than 0.
When str1 < STR2, the return value is less than 0.
Nine: string-case conversion strtolower (); Strtoupper (); Ucfirst (); Ucwords ();
$str"I AM PETAL";echo strtolower($str)."
"; //大写转换为小写$stra"i am petal";echo strtoupper($stra)."
"// 小卫转换为大写echo ucfirst($stra)."
"; //只将字符串的第一个字符转换为大写echo ucwords($stra); //将字符串每一个单词的首字母转换为大写
The results are as follows
The above describes the PHP string function (3), including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.