Ways to remove characters and trailing spaces in PHP _php tutorial

Source: Internet
Author: User
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? $...

  • 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.