-
/**
- * PHP String Function Example
- * by bbs.it-home.org
- */
-
$str 1= "ABCD";
- Print ($str 1);//output function, with return result (string), Speed no echo fast!
-
It can be said that ECHO is not a PHP function
- Print_r ($STR);//output function, typically used for testing
- echo "
****
". Ord ($str 1)."
";
- $str 2= "ABCD";
- echo "
****
". Ord ($str 2)."
";
-
Echo strcmp ($str 2, $str 1); The ASCII value of the first letter a of//STR1 is greater than the ASCII value of the first letter of the STR2
- is return 1, not return-1, the same letter ASCII value continues to compare! Exactly the same return 0
- echo "
";
-
echo Substr_count ("ABCD Bcxx", "BC");//statistics string BC in front of the character wearing the number of occurrences, no return 0
- echo Substr_count ("ABCD Bcxx", "BC", 3,4);//Statistics string BC from the preceding string, the 3rd character starts to the number of//,BC occurrences in the following 4 characters, no return 0
- echo Substr_count ("ABCD Bcxx", "BC", 3,8);//Error exceeding length
-
echo "
Strpos, Strrpos functions
";
- Echo Strpos ("ABCDE", "BC");//Represents the first occurrence of the BC string in the ABCDE string, no return null appears
- Echo Strrpos ("ABCDE", "BC1");//Indicates the last occurrence of the BC string in the ABCDE string, and no return null appears
-
echo "
STRSTR, STRRCHR functions
";
- Echo strstr ("abced", "BC");//output string BC starts at the first occurrence of the abced string to the following string, no return null
- echo "
";
- Echo strrchr ("bcabced", "1");//output string BC1 starts at the last occurrence of the abced string to the following string, does not take the first character, finds it in the preceding string, finds it, and returns if
- No return null found
- Echo strrchr ("bcabced China", "medium");
-
echo "
NL2BR function
";
- $str = "afdgdsa\r\n1111";
- echo nl2br ($STR);//convert escape carriage return to HTML
-
echo "
Str_repalce function
";
- echo $str = "DSFSD sdfsdf 233";
- echo "\ t The original string length is:". strlen ($STR). "
";
- Echo strlen (Str_replace ("", "", $str));//Find a space in the STR string instead of a string, such as finding a string that has no characters to replace, will not be manipulated!!
- $str = "[Dsfsdf]sdfsdf[sdfsdf]";
- $arr 1=array ("{", "}");
- $arr 2=array ("(");
- $str =str_replace ($arr 1, $arr 2, $STR);
- Echo $str;
-
echo "
substr function
";
- echo substr ("Abcddsfds", 2). "
";//a character that is truncated to the end of a string starting from the 2nd position
- echo substr ("Abcddsfds", 2,20);//20 characters from the beginning of the 2nd position intercept to the string
-
echo "
Explode, str_split functions
";
- $str = "1,2,3,4,5,";
- Print_r (Explode ("(", $str));//To, split string, no split character, directly return string
- foreach (Explode (",", $str) as $v) {
- echo $v. " \ t ";
- }
- $str = "1,2,3,4,5,";
- echo "
";
- Print_r (Explode ("2", $str, 4));
- echo "
";
- $STR = "Scripting Academy 22222";
- Print_r (Str_split ($STR, 2));//Split the string with 2 bytes, does not support the segmentation of Chinese characters
- ?>
-
Copy Code |