Summary of some strings in php and summary of php Strings
Php comes with a function to intercept strings. It can only process English characters, and numbers cannot intercept Chinese characters. If you need it, you can refer to it. It is easier to use later, the first is intended for beginners.
Php // construct the string $ str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; echo "original string :". $ str. ""; // intercept in various ways $ str1 = substr ($ str, 5); echo "starts from 5th characters to the end :". $ str1. "; $ str2 = substr ($ str, 9, 4); echo" starts from 9th characters and starts with 4 characters :". $ str2. "; $ str3 = substr ($ str,-5); echo" returns the last five characters :". $ str3. ""; $ str4 = substr ($ str,-8th); echo "returns four characters from the last characters :". $ str4. ""; $ str5 = substr ($ str,-8,-2); echo "starts from the last 8th characters to the last 2nd characters :". $ str5. "";?>
Supports intercept between Chinese and English./* ---------------------------------------------------- Parameter: $ str_cut string to be truncated $ length the maximum length allowed for string display function: intercept width and halfwidth (Chinese and English) mixed strings to avoid garbled characters. */function substr_cut ($ str_cut, $ length) {if (strlen ($ str_cut)> $ length) {for ($ I = 0; $ I <$ length; $ I ++) if (ord ($ str_cut [$ I])> 128) $ I ++; $ str_cut = substr ($ str_cut, 0, $ I ). ".. ";}return $ str_cut ;}?>
1. // string inversion Function$ Str = 'hello'; // ----> ollehecho strrev ($ str ). '<br/>'; // This is a function provided by the system. // write a function to reverse it. $ strArr = str_split ($ str ); // Array ([0] => h [1] => e [2] => l [3] => l [4] => o) $ str1 = ''; for ($ I = count ($ strArr)-1; $ I >=0; $ I --) {$ str1. = $ strArr [$ I];} echo $ str1;2. // get the file suffix. jpg or jpg.Using file='abc.exe.jpg '; echo strrchr ($ file ,'. '). '<br/>'; // the system function used. Find the file name echo strrev (strstr (strrev ($ file ),'. ', true )). '<br/>'; // strstr () returns the first occurrence of a string. If true is added, the returned result is. previous string echo substr ($ file, strrpos ($ file ,'. ')). '<br/>'; // strrpos () returns the last time. and then intercept $ strArr = explode ('. ', $ file); echo $ strArr [count ($ strArr)-1]. '<br/>'; // The explode () function splits the string into an array by point. // echo array_pop ($ strArr ). '<br/>'; // echo end ($ strArr ). '<br/>'; echo pathinfo ($ file, PATHINFO_EXTENSION ). '<br/>'; // The information returned by the pathinfo () function is the file path echo strrev (substr (strrev ($ file), 0, strpos ($ file ,'. '))). '<br/> ';3. // set 1234567890 -----> 1,234,567,890$ Str = '000000'; $ strArr = str_split (strrev ($ str), 3); echo strrev (implode (',', $ strArr )). '<br/>'; // ----> 1,234,567,890