PHP Chinese processing function assembly _ PHP Tutorial

Source: Internet
Author: User
Describes in detail the collection of PHP Chinese processing functions. --- Space in the PHP Chinese processing function --- stringGBspace (string) --------- add a space between each Chinese character stringGBunspace (string) ------- clear the string between spaces

--- Space of PHP Chinese processing functions ---

String GBspace (string) --------- add a space between each text
String GBunspace (string) ------- clear spaces between each text
String clear_space (string) ------- used to clear unnecessary spaces

--- Converting PHP Chinese processing functions ---

String GBcase (string, offset) --- converts Chinese and English characters in the string into uppercase and lowercase letters.
Offset: "upper"-converts all strings to uppercase (strtoupper)
"Lower"-converts all strings to lowercase (strtolower)
"Ucwords"-change the first letter of each character in the string to uppercase (ucwords)
"Ucfirst"-change the first letter of the string to uppercase (ucfirst)
String GBrev (string) ----------- reverse string

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

Int GB_check (string) ----------- check whether the string contains GB characters. If yes, true is returned,
Otherwise, false is returned.
Int GB_all (string) ------------- check whether all characters in the string contain GB characters. true is returned,
Otherwise, false is returned.
Int GB_non (string) ------------- check whether all characters in the string are not GB characters. true is returned,
Otherwise, false is returned.
Int GBlen (string) -------------- returns the string length (only one letter in Chinese)

--- Search, replace, and extract PHP Chinese processing functions ---

Int/array GBpos (haystack, needle, [offset]) ---- query string (strpos)
Offset: leave it blank-search for the first position
Int-search for the first location from this location
"R"-find the last position (strrpos)
"A"-save all searched words as an array (return array)

String GB_replace (needle, str, haystack) -- Search for and replace a string (str_replace)
String GB_replace_ I (needle, str_f, str_ B, haystack) -- do not check case sensitivity to search for and replace strings
Needle-search for letters
Str-replace the letter (str_f-before and after the letter str_ B)
Haystack-string

String GBsubstr (string, start, [length]) -- extract from string the length from start to end or
Length string.
Only one letter in the text, positive or negative.
String GBstrnear (string, length) -- extract the string closest to length from string.
Length is a string of 2 letters.

--- Notes for PHP Chinese processing functions ---

If you want to use the string returned by Form, perform stripslashes () processing on the string first to remove unnecessary strings.

Usage: add the following in the original PHP code:
Include ("GB. inc ");
You can use the above tool functions.

 
 
  1. */
  2. < ?php
  3. function GBlen($string) {
  4. $l = strlen($string);
  5. $ptr = 0;
  6. $a = 0;
  7. while ($a < $l) {
  8. $ch = substr($string,$a,1);
  9. $ch2 = substr($string,$a+1,1);
  10. if (ord($ch) >= HexDec("0x81")
    && ord($ch2) >= HexDec("0x40")) {
  11. $ptr++;
  12. $a += 2;
  13. } else {
  14. $ptr++;
  15. $a++;
  16. } // END IF
  17. } // END WHI?
  18. ?>


Http://www.bkjia.com/PHPjc/445919.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445919.htmlTechArticle --- PHP Chinese processing function space --- string GBspace (string) --------- add a space between each text string GBunspace (string) ------- the space between each text clear string...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.