-
-
/** - * PHP string function example
- * by bbs.it-home.org
- */
$str1="aBCD";
- print($str1);//Output The function returns a result (string) and is not as fast as echo!
//It can be said that echo is not a PHP function
- print_r($str);//Output function, generally used for testing
- echo "
**** " .ord($str1)." ";
- $str2="aBCD";
- echo "
**** ".ord($str2)." ";
echo strcmp($str2,$str1);//Whether the ASCII code value of the first letter a of str1 is greater than the ASCII code value of the first letter of str2
- //is return 1, instead of returning -1, the same letter ASCII code value continues to be compared! Exactly the same and returns 0
- echo "
";
echo substr_count("abcd bcxx","bc");//Count the number of times the string bc appears in front of the character , no 0 is returned
- //echo substr_count("abcd bcxx","bc",3,4);//The statistical string bc starts from the 3rd character in the previous string to the next 4 characters// , the number of occurrences of bc does not return 0
- //echo substr_count("abcd bcxx","bc",3,8);//exceeded length error
echo " strpos, strrpos function ";
- echo strpos("abcde","bc");//The position of the first occurrence of the bc string represented in the abcde string, if it does not appear, return null
- echo strrpos( "abcde","bc1");//Indicates the position where the bc string last appeared in the abcde string. If it does not appear, return null
echo " strstr, strrchr function< ;Br>";
- //echo strstr("abced","bc");//The output string bc starts from the position where the abced string first appears to the following string, and does not return null
- echo "< br>";
- echo strrchr("bcabced","1");//The output string bc1 starts from the last occurrence of the abced string to the following string, without taking the first character, and proceeds in the previous string Search, find and return, if it is still not found, return null
- echo strrchr("bcabcedChina","中");
echo " nl2br function ";
- $str="afdgdsarn1111";
- echo nl2br($str);//Convert escaped carriage return, line feed, etc. to html
echo " ";
- echo $str=" dsfsd sdfsdf 233 ";
- echo "tThe length of the original string is: ".strlen($str)."
";
- echo strlen( str_replace(" ","",$str));//Look for spaces in str string and replace them with non-existent strings. If the searched string does not have characters to be replaced, no operation will be performed! !
- $str="[dsfsdf]sdfsdf[sdfsdf]";
- $arr1=array("{","}");
- $arr2=array("(");
- $str=str_replace($arr1,$ arr2,$str);
- echo $str;
echo " substr function ";
- echo substr("abcddsfds",2)."
- echo substr("abcddsfds",2,20);//Intercept from the 2nd position to the 20 characters of the string
echo " explode, str_split function ";
- $str="1,2,3,4,5,";
- print_r(explode("(",$str ));//Split the string with, without splitting characters, return the string directly
- foreach(explode(",",$str) as $v){
- echo $v."t";
- }
- $ str="1,2,3,4,5,";
- echo "
";
- print_r(explode("2",$str,4));
- echo "
";
- $str="Script Academy 22222";
- print_r(str_split($str,2));//Split the string by 2 bytes, splitting of Chinese characters is not supported
- ?>
-
-
-
Copy code
|