Home >Backend Development >PHP Tutorial >Detailed introduction to the collection of PHP Chinese processing functions_PHP tutorial

Detailed introduction to the collection of PHP Chinese processing functions_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:35:131061browse

--- PHP Chinese processing function for spaces ---

string GBspace(string) --- ------ Add a space between each Chinese character
string GBunspace(string) ------- Clear the space between each Chinese character
string clear_space(string) ---- --- Used to remove extra spaces

--- PHP Chinese processing function conversion ---

string GBcase(string,offset) --- Will Convert Chinese and English characters in the string to uppercase and lowercase
offset: "upper" - Convert the string to all uppercase (strtoupper)
"lower" - Convert all the string to 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

--- PHP Chinese processing function text check---

int GB_check(string) ------- ---- Check whether there is GB word in the string, if so it will return true,
otherwise it will return false
int GB_all(string) ------------- Check the string Whether all words have GB characters will return true,
otherwise it will return false
int GB_non(string) ------------- Check that all words in the string are not GB characters , it will return true,
otherwise it will return false
int GBlen(string) -------------- Returns the length of the string (Chinese characters only count one letter)

--- PHP Chinese processing function search, replacement, extraction---

int/array GBpos(haystack,needle,[offset]) ---- Find characters String (strpos)
offset: Leave blank - find the first occurrence position
int - search the first occurrence position from this 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 a string from start to end or length
length from 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 characters total 2 letters.

---Notes on PHP Chinese processing functions---

If you use the string returned by Form, please first process the string with stripslashes() , remove the excess.

Usage: Add:
include ("GB.inc");
to the original PHP code to use the above tool functions.

<ol class="dp-xml">
<li class="alt"><span><span>*/  </span></span></li>
<li>
<span class="tag"><</span><span> ?php  </span></li><li class="alt"><span>function GBlen($string) {  </span></li><li><span>$</span><span class="attribute">l</span><span> = </span><span class="attribute-value">strlen</span><span>($string);  </span></li><li class="alt"><span>$</span><span class="attribute">ptr</span><span> = </span><span class="attribute-value">0</span><span>;  </span></li><li><span>$</span><span class="attribute">a</span><span> = </span><span class="attribute-value">0</span><span>;  </span></li><li class="alt"><span>while ($a </span><span class="tag"><</span><span> $l) {  </span></li><li><span>$</span><span class="attribute">ch</span><span> = </span><span class="attribute-value">substr</span><span>($string,$a,1);  </span></li><li class="alt"><span>$</span><span class="attribute">ch2</span><span> = </span><span class="attribute-value">substr</span><span>($string,$a+1,1);  </span></li><li><span>if (ord($ch) </span><span class="tag">></span><span>= HexDec("0x81") <br>&& ord($ch2) </span><span class="tag">></span><span>= HexDec("0x40")) {  </span>
</li>
<li class="alt"><span>$ptr++;  </span></li>
<li><span>$a += 2;  </span></li>
<li class="alt"><span>} else {  </span></li>
<li><span>$ptr++;  </span></li>
<li class="alt"><span>$a++;  </span></li>
<li><span>} // END IF  </span></li>
<li class="alt"><span>} // END WHI?  </span></li>
<li>
<span class="tag">?></span><span>   </span>
</li>
</ol>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445919.htmlTechArticle--- PHP Chinese processing function for spaces--- string GBspace(string) ------- -- Add spaces between each Chinese character string GBunspace(string) ------- Clear spaces between each Chinese character 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