What to do if php trim() cannot remove spaces

coldplay.xixi
Release: 2023-03-04 17:04:02
Original
3670 people have browsed it

Solution to the problem that php trim() cannot remove the spaces: Use regular expressions to remove the spaces at the beginning of the string, including full-width and half-width, the code is [$user = mb_ereg_replace('^( | ) ',' ', $name)].

What to do if php trim() cannot remove spaces

Solution to the problem that php trim() cannot remove spaces:

php’s trim() is the one we use most String space removal function, but trim() cannot remove half-width spaces. At this time, you need to take other methods

This regular expression can remove the first space in the string , regardless of full-width or half-width

The code is as follows:

  $user = mb_ereg_replace('^( | )+','', $name);
Copy after login
  $user = mb_ereg_replace('( | )+$','', $name);
Copy after login

Related learning recommendations: php programming (video)

The above is the detailed content of What to do if php trim() cannot remove spaces. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!