php Chinese processing tool function --- Space ---
string GBspace(string) --------- Add space between each Chinese character
string GBunspace(string) ------- Clear spaces between each Chinese character
string clear_space(string) ------- Used to clear excess spaces
--- Conversion ---
string GBcase(string,offset) --- Convert the Chinese and English characters in the string to uppercase and lowercase
offset: "upper" - Convert the string to all uppercase (strtoupper)
"lower" - Convert the string to all lowercase (strtolower)
"ucwords" - Change the first letter of each word in the string to uppercase (ucwords)
"ucfirst" - Change the first letter of the string to uppercase (ucfirst)
string GBrev(string) --- -------- Reverse string
--- Text check ---
int GB_check(string) ----------- Check whether there is GB word in the string, If possible, it will return true,
Otherwise, it will return false
int GB_all(string) ------------- Check whether all words in the string have GB characters, if so, it will return true,
Otherwise it will return false
int GB_non(string) ------------- Check if all the words in the string are not GB words, it will return true,
Otherwise it will return false
int GBlen(string) -------------- Return the length of the string (Chinese characters only count one letter)
---Search, replace, extract---
int/array GBpos(haystack,needle,[offset]) ---- Search string (strpos)
offset: Leave blank - find the first occurrence of the position
int - search for occurrences from this position First position
"r" - Find the last occurrence position (strrpos)
"a" - Store all found words as an array (return array)
string GB_replace(needle,str, haystack) -- Find and replace strings (str_replace)
string GB_replace_i(needle,str_f,str_b,haystack) -- Find and replace strings without checking case
needle - Find letters
str - Replace Letters (str_f - before the letter, str_b after the letter)
haystack - string
string GBsubstr(string,start,[length]) -- extract from the string from start to end or length
length string.
Chinese characters only count one letter, and positive and negative numbers can be used.
string GBstrnear(string,length) – Extract the string closest to length from string.
length Chinese Chinese characters are 2 letters long.
--- Note ---
Before using the string returned by Form, please stripslashes() the string first to remove redundant ones.
Usage: Add:
include ("GB.inc");
to the original PHP code to use the above tool functions.
*/
Copy PHP content to clipboard
function GBlen($string) {
$l = strlen($string);
$ptr = 0 ;
$a = 0;
while ($a < $l) {
$ch = substr($string,$a,1);
$ch2 = substr($string, $a+1,1);
if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
$ptr++;
$a += 2;
} else {
$ptr++;
$a++;
} // END IF
} // END WHI?
?>