How to remove the string and the trailing blanks in PHP _php tutorial

Source: Internet
Author: User
Tags rtrim
The first method: a function that comes with PHP
/*
Trim removes a string at both ends of a space,
RTrim is to remove a string to the right of the space,
LTrim is to remove the left space of a string.

*/
?>
Echo Trim ("space"). "
";
echo RTrim ("Space"). "
";
Echo LTrim ("Space"). "
";
?>
Second method: Replace with regular expression, more powerful
PHP removes string and trailing spaces (including full-width)
Copy CodeThe code is as follows:
$str = "Script House www.jb51.net";
$str = Mb_ereg_replace (' ^ (|) + ', ', $str);
$str = Mb_ereg_replace (' (|) +$ ', ', $str);
Echo mb_ereg_replace (', ' \ n ', $str);
?>

http://www.bkjia.com/PHPjc/325449.html www.bkjia.com true http://www.bkjia.com/PHPjc/325449.html techarticle the first method: via PHP's own function? PHP/* Trim removes a string at both ends of a space, RTrim is a string to remove the right space, and LTrim is to strip the left space of a string. ...

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