During the development process, we often encounter the problem of intercepting Chinese and English numbers. We all know that Chinese characters are different from English numbers; then, we will write some daily functions in the project's common, including the time calculation conversion and the functions intercepted by Chinese and English characters; for example, there are not a few lines of code to intercept Chinese and English functions.
During the development process, we often encounter the problem of intercepting Chinese and English numbers. We all know that Chinese characters are different from English numbers; then, we will write some daily functions in the project's common, including the time calculation conversion and the functions intercepted by Chinese and English characters; for example, there are not a few lines of code to intercept Chinese and English functions.
During the development process, we often encounter the problem of intercepting Chinese and English numbers. We all know that Chinese characters are different from English numbers; then, we will write some daily functions in the project's common, including the time calculation conversion and the functions intercepted by Chinese and English characters; for example, I'm afraid I can't take a few lines of code for intercepting Chinese and English functions. Now I want to tell you a simple one (I have run it locally). If you have any questions, please kindly advise.
$ C = 'ddaabbccaa '; $ d = 'Earth needs the love of each of us'; $ frist1 = mb_substr ($ c, 0, 1, "UTF-8 "); // d $ delete_last1 = mb_substr ($ d,-, "UTF-8"); // echo $ frist1. '++ '. $ delete_last1.'
'; // D ++ $ frist2 = mb_substr ($ d, 0, 1, "UTF-8"); // $ delete_last2 = mb_substr ($ d, "UTF-8"); // echo $ frist2. '++ '. $ delete_last2.'
'; // Region ++ protection $ e = '11aa22cc33'; $ f = 'aa Earth needs the love of each of us '; $ g = 'Earth needs the love of each of us gg'; $ h = 'Earth needs the love of each of us '; $ first3 = mb_substr ($ e, 0, 1, "UTF-8"); // 1 $ last3 = mb_substr ($ f, 0, 1, "UTF-8"); // a $ delete_last3 = mb_substr ($ f, "UTF-8"); // $ e_last4 = mb_substr ($ g,-, "UTF-8"); // g $ frist4 = mb_substr ($ g, 0, 1, "UTF-8"); // $ delete_last5 = mb_substr ($ h,-, "UTF-8"); // echo $ first3. '+ + + '. $ last3 .'---'. $ delete_last3. '***'. $ delete_last4. '&&&'. $ frist4 .'
'; // 1 ++ a --- protection *** g & amp; echo $ last3.'... '. $ delete_last3 .'
'; // A... echo $ frist4.'... '. $ delete_last5 .'
'; // Location... this way, no matter whether the string contains Chinese and English numbers, you do not need to judge, for example, "location... protection "or" location... "or"... protection"
PS: used to filter spaces in a string
To remove spaces between the beginning and end of a string:
function mbTrim($str) { return mb_ereg_replace('(^( | )+|( | )+$)', '', $str); }
During the following regular expression verification, consecutive spaces entered by the user are filtered out, including fullwidth spaces and halfwidth 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);