The following article to give you a summary of a number of PHP to remove the string end-to-end Chinese and English space program examples, here useful regular replacement and trim series function Delete, below we take a look.
Example 1.trim function to remove a space
The trim () function is used to remove spaces at the beginning and end of a string, and returns a string after the space is stripped. The syntax is as follows:
String Trim (String str[,string charlist]);
The LTrim () function is used to remove spaces to the left of a string or to specify a string. The syntax is as follows:
String LTrim (String str[,string charlist]);
The RTrim () function is used to remove spaces and special characters to the right of a string. The syntax is as follows:
String RTrim (String str[,string charlist]);
The code is as follows |
Copy Code |
$a = "(A,b,c,)"; echo $a. " "; Output: (A,b,c,) $b =trim ($a, "()"); Remove the character "(" or ")" from the end of the string echo $b. " "; Output: A,b,c, $c =trim ($a, "(,)"); Remove the character "(", "," or ")" from the end of the string echo $c. " "; Output: A,b,c
?>
|
Output Result:
(A,b,c,)
A,b,c,
A,b,c
In SQL, function trim () is used to remove the leading and trailing spaces, LTrim () to remove the left space of the string, and RTrim () to remove the right space from the string.
Example 2. Using the Str_replace regular replacement
The code is as follows |
Copy Code |
function Mbtrim ($STR) { Return Mb_ereg_replace (' (^ (|) +| | +$) ', ', $str); } |
Example 3.str_replace Regular replacement
The code is as follows |
Copy Code |
$str = "www.bKjia.c0m"; $str = Mb_ereg_replace (' ^ (|) + ', ', $str); $str = Mb_ereg_replace (' (|) +$ ', ', $str); Echo mb_ereg_replace (', ' n ', $str); ?> |
http://www.bkjia.com/PHPjc/632753.html www.bkjia.com true http://www.bkjia.com/PHPjc/632753.html techarticle the following article to give you a summary of a number of PHP to remove the string end-to-end Chinese and English space program examples, here useful regular replacement and trim series function Delete, below we take a look. Example ...