PHP String Functions (3)

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.