For a summary of some strings in PHP, PHP string Summary
PHP comes with a truncated string function, can only handle English, the number can not intercept the Chinese mixed, oh, there is a need for friends to refer to, the latter is more useful, the first is mainly for beginners to learn to use.
PHP//construct string $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; echo "Original string:". $str. ""; Interception by various means $str 1 = substr ($STR, 5); echo "starts from the 5th character to the last:". $str 1. ""; $str 2 = substr ($str, 9,4); echo "takes 4 characters starting from the 9th character:". $str 2. ""; $str 3 = substr ($str,-5); echo "Take the last 5 characters:". $str 3. ""; $str 4 = substr ($str, -8,4); echo "takes 4 characters backwards from the last 8th character:". $str 4. ""; $str 5 = substr ($str, -8,-2); echo "starts from the 8th character to the bottom of the 2nd character:". $str 5. "; ?>
Support mixed interception in Chinese and English./*------------------------------------------------------parameter: $str _cut The string to be truncated $length Maximum length allowed for string display program features: Capture full-width and half-width (kanji and English) mixed strings to avoid garbled------------------------------------------------------*/function Substr_cut ($str _cut, $length) { if (strlen ($str _cut) > $length) {for ($i =0; $i < $length; $i + +) if (Ord ($str _cut[$i]) > $i + +; $str _cut = substr ($str _cut,0, $i). ".."; } return $str _cut;}? >
1.//the inverse function of a string$str = ' Hello ';//---->ollehecho Strrev ($str). '
';///This is the system-provided function//down to write a function to implement the reversal $strarr = Str_split ($STR);//array ([0] = h [1] = e [2] = l [3] = l [4] => ; o) $str 1= '; for ($i =count ($STRARR)-1; $i >=0; $i-) {$str 1.= $strArr [$i];} echo $str 1;2.//Gets the suffix name of the file. jpg or jpg can be$file = ' abc.exe.jpg '; Echo strrchr ($file, '. '). '
';//This is the system function used to find the filename of Echo strrev (Strstr (Strrev ($file), '. ', True)). '
';//strstr () returns the first occurrence of a string, plus true to indicate that it is returned. Before the string echo substr ($file, Strrpos ($file, '. ')). '
';//strrpos () returns the last occurrence of the position, and then the interception $strArr =explode ('. ', $file); Echo $strArr [Count ($STRARR)-1]. '
The//explode () function divides a string into an array of dots//echo array_pop ($strArr). '
';//echo end ($STRARR). '
'; Echo PathInfo ($file, pathinfo_extension). '
The ';//pathinfo () function returns the information for the path of the file Echo Strrev (substr (Strrev ($file), 0,strpos ($file, '. '))). '
';3.//will 1234567890----->1,234,567,890$str = ' 1234567890 '; $strArr =str_split (Strrev ($STR), 3), Echo Strrev (Implode (', ', $STRARR)). '
';//---->1,234,567,890
http://www.bkjia.com/PHPjc/1123804.html www.bkjia.com true http://www.bkjia.com/PHPjc/1123804.html techarticle some of the string in PHP Summary, PHP string summary php comes with a truncated string function, can only handle English, the number can not intercept the Chinese mix of the Oh, the need for friends ...