Instance
The code is as follows: |
Copy code |
<? $ Str = "webpage creation tutorial www.111cn.net "; $ 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 mb_ereg_replace.
Mb_ereg_replace () we only need to pay attention to the above mb. Some friends can see that this function supports Chinese characters after reading character conversion.
Some may ask if php has its own function. Let's look at the example below.
Instance
The code is as follows: |
Copy code |
<? Php $ Str = "Remove leading and trailing spaces "; Echo "the original string is in square brackets: [". $ str. "] <br> "; Echo "original string length:". strlen ($ str). "<br> "; $ Str1 = ltrim ($ str ); Echo "length after ltrim () execution:". strlen ($ str1). "<br> "; $ Str2 = rtrim ($ str ); Echo "length after rtrim () execution:". strlen ($ str2). "<br> "; $ Str3 = trim ($ str ); Echo "length after trim () execution:". strlen ($ str3). "<br> "; Echo "remove the string after the beginning and end spaces: [". $ str3. "]"; ?> |
Summary: there are multiple solutions to the same problem. Just like deleting spaces, we can use two different methods to achieve the same effect.