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