How to remove spaces at the beginning and end of a string in php
WBOYOriginal
2016-07-25 09:05:271205browse
/*
trim removes spaces from both ends of a string,
rtrim removes spaces from the right of a string,
ltrim removes spaces from the left of a string.
*/
echo trim("space")." ";
echo rtrim("space")." ";
echo ltrim("space")." ";
?>
Copy code
Method 2: Replace with regular expression, more powerful. PHP removes spaces from the beginning and end of a string (including full-width)
$str=" Script Academy bbs.it-home.org ";
$str = mb_ereg_replace('^( | )+', '', $str);
$str = mb_ereg_replace('(|
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn