In the course of our development, we often encounter problems in the interception of Chinese and English numerals, and we know that Chinese characters and English numerals are different; and then we'll write some everyday functions in the common of the project. Functions including time calculation conversion and Chinese-English character interception , such as the interception of the English function is not a few lines of code I'm afraid you can not get down the bar, now tell everyone a simple (their own local running), if there is a problem, please advise the
$c = ' DDAABBCCAA ';
$d = ' Earth needs the love of each of us '; $frist 1 = mb_substr ($c, 0, 1, "UTF-8"); D $delete _last1 = Mb_substr ($d, -1,1, "UTF-8"); Guard echo $frist 1. ' +++ '. $delete _last1. ' <br/> '; d+++ $frist 2 = mb_substr ($d, 0, 1, "UTF-8"); Ground $delete _last2 = Mb_substr ($d, -1,1, "UTF-8"); Guard echo $frist 2. ' +++ '. $delete _last2. ' <br/> ';
+++ to protect $e = ' 11aa22cc33 ';
$f = ' AA Earth needs the love of each of us ';
$g = ' Earth needs every one of us to love GG ';
$h = ' Earth needs the love of each of us '; $first 3 = mb_substr ($e, 0, 1, "UTF-8"); 1 $last 3 = mb_substr ($f, 0, 1, "UTF-8"); A $delete _last3 = Mb_substr ($f, -1,1, "UTF-8"); Protective $delete _last4 = Mb_substr ($g, -1,1, "UTF-8"); G $frist 4 = mb_substr ($g, 0, 1, "UTF-8"); Ground $delete _LAST5 = Mb_substr ($h, -1,1, "UTF-8"); Guard echo $first 3. ' +++ '. $last 3. '---'. $delete _last3. ' '. $delete _last4. ' &&& '. $frist 4. ' <br/> '; 1+++a---***g&&& echo $last 3. ' ... '. $delete _last3. ' <br/> '; A... Guard echo $frist 4. ' ... '. $delete _last5. ' <br/> '; To ... Protect//So regardless of stringBoth Chinese and English numerals are available without judgment, such as: "Ground ... Protect "or" ground ... " Or "...
Supporting
PS: A method of filtering the hollow lattice of strings
How to remove the English spaces in the end of a string:
function Mbtrim ($str)
{return
mb_ereg_replace (' ^ (|) +| | +$) ', ', $str);
The following regular validation filters out consecutive spaces entered by the user, including full-width spaces and half-width spaces
$user = Mb_ereg_replace (' ^ (|) + ', ', $user);
$user = Mb_ereg_replace (' (|) +$ ', ', $user);
$age = Mb_ereg_replace (' ^ (|) + ', ', $age);
$age = Mb_ereg_replace (' (|) +$ ', ', $age);
$method = Mb_ereg_replace (' ^ (|) + ', ', $method);
$method = Mb_ereg_replace (' (|) +$ ', ', $method);
$address = Mb_ereg_replace (' ^ (|) + ', ', $address);
$address = Mb_ereg_replace (' (|) +$ ', ', $address);