PHP Chinese processing function Collection _php skills

Source: Internet
Author: User
Tags lowercase ord
---space---
String Gbspace (String)---------space between each Chinese text
String Gbunspace (String)-------space clearance between text in each
String Clear_space (String)-------to clear extra spaces

---conversion---
String gbcase (String,offset)---Converts English text within a string to uppercase and lowercase
Offset: "Upper"-full capitalization of strings (Strtoupper)
"Lower"-string all lowercase (strtolower)
"Ucwords"-capitalize the first letter of each word in a string (ucwords)
"Ucfirst"-capitalize the first letter of the string (Ucfirst)
String Gbrev (String)-----------invert strings

---text check---
int Gb_check (string)-----------check for GB characters within the string, and returns True.
Otherwise it will return false
The int gb_all (string)-------------checks that all words in the string have GB characters and returns true.
Otherwise it will return false
int Gb_non (String)-------------checks that all words in a string are not GB and returns True.
Otherwise it will return false
int Gblen (String)--------------return string length (only one letter in Chinese text)

---find, replace, extract---
Int/array Gbpos (Haystack,needle,[offset])----Find string (Strpos)
Offset: Leave blank-Find the first position to appear
INT-Search By this location for the first position that appears
"R"-Find the last place to appear (Strrpos)
"A"-stores all found words in an array (returns an array)

String Gb_replace (Needle,str,haystack)--Find and replace strings (Str_replace)
String Gb_replace_i (Needle,str_f,str_b,haystack)--Do not check case lookup and replace string
Needle-Find letters
STR-Replaces the letter (Str_f-Before the letter, str_b the letter)
Haystack-strings

String Gbsubstr (String,start,[length])--extracts from a string from start to end or length
Length of the string.
Medium text is counted as a single letter, and positive numbers can be used.
String Gbstrnear (string,length)-extracts the string closest to length from string.
Length in 2 letters in the text count.

---notice---
If you use a string that is returned by Form, you can Stripslashes () the string before removing the redundant \.

Usage: Add in the original PHP code:
Include ("Gb.inc");
You can use the above tool functions.
*/
Copy PHP content to clipboard

<?php
function Gblen ($string) {
$l = strlen ($string);
$ptr = 0;
$a = 0;
while ($a < $l) {
$ch = substr ($string, $a, 1);
$ch 2 = substr ($string, $a +1,1);
if (Ord ($ch) >= hexdec ("0x81") && Ord ($ch 2) >= hexdec ("0x40")) {
$ptr + +;
$a + 2;
} else {
$ptr + +;
$a + +;
}//End IF
}//End WHI?
?>

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.