Home  >  Article  >  Backend Development  >  PHP Chinese processing function collection_PHP tutorial

PHP Chinese processing function collection_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:49:53796browse

--- Space ---
string GBspace(string) --------- Add space between each Chinese character
string GBunspace(string) ------- Each Chinese character Clear spaces between words
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 the string

--- Text check---
int GB_check(string) ----------- Check whether there is a string in the string If it contains GB characters, 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 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]) ---- Find string (strpos)
offset: Leave blank - find the first occurrence of
int - Search for the first occurrence of this position
"r" - Find the last occurrence of the 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]) -- from string Extract a string from start to end or length
length.
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 excess.

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?
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319462.htmlTechArticle--- Space --- string GBspace(string) --------- Each Chinese Add spaces between characters string GBunspace(string) ------- Clear spaces between each Chinese character string clear_space(string) -----...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn