There are a lot of ways to remove character space in PHP, and I'll show you how to handle the three functions using Mb_ereg_replace () and Ltrim,rtrim,trim.
Instance
The code is as follows |
Copy Code |
$STR = "Web page making tutorial www.bKjia.c0m"; $str = Mb_ereg_replace (' ^ (|) + ', ', $str); $str = Mb_ereg_replace (' (|) +$ ', ', $str); Echo mb_ereg_replace (', ' n ', $str); ?> |
Some friends may not understand mb_ereg_replace (), let's introduce the function of Mb_ereg_replace.
Mb_ereg_replace () We just have to pay attention to the previous MB, some friends have used the character conversion to understand that this function is supported in Chinese.
Some friends will ask PHP does not have its own function, below we look at the example
Instance
The code is as follows |
Copy Code |
$STR = "Remove space before and after"; echo "The original string in square brackets: [". $str. "] "; echo "Raw string length:". strlen ($STR). " "; $str 1=ltrim ($STR); echo "Executes the length after LTrim ():". strlen ($str 1). " "; $str 2=rtrim ($STR); echo "Executes the length after RTrim ():". strlen ($str 2). " "; $str 3=trim ($STR); echo "The length after the trim () is performed:". strlen ($str 3). " "; echo "Remove the string after the trailing space: [". $str 3. "]"; ?> |
Summary: The same problem will have a variety of solutions, as we delete the word spaces, you can use two different methods to achieve the desired effect.
http://www.bkjia.com/PHPjc/629135.html www.bkjia.com true http://www.bkjia.com/PHPjc/629135.html techarticle There are a lot of ways to remove character space in PHP, and I'll show you how to handle the three functions using Mb_ereg_replace () and Ltrim,rtrim,trim. Example code copy Code as follows? $...