PHP specifies an instance of a _php instance sharing a Chinese or numeric character in an intercept string

Source: Internet
Author: User
Tags numeric

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); 

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.