Home  >  Article  >  Backend Development  >  How to remove spaces in php string

How to remove spaces in php string

藏色散人
藏色散人Original
2020-10-30 10:08:542763browse

How to remove spaces from strings in php: 1. Use the trim function to remove spaces at both ends of the string; 2. Use ltrim to remove only the first spaces in the string; 3. Use the rtrim function to convert to remove spaces.

How to remove spaces in php string

Recommended: "PHP Video Tutorial"

You can use trim to remove spaces at the beginning and end of the string. The following characters There is a space at the beginning and end of the string "my name is haha".

How to remove spaces in php string

After trim conversion, the spaces at both ends are removed.

How to remove spaces in php string

You can use ltrim to remove only the first space in the string. The following string "my name is haha" has a space in the first part.

How to remove spaces in php string

After conversion through ltrim, the leading spaces are removed, but the trailing spaces are still there.

How to remove spaces in php string

You can use ltrim to remove only the trailing spaces in the string. There is a trailing space in the following string "my name is haha".

How to remove spaces in php string

After conversion through rtrim, the trailing spaces are removed, but the leading spaces are still there.

How to remove spaces in php string

Notes

Spaces often cause program logic processing problems and often need to be removed

The above is the detailed content of How to remove spaces in php string. For more information, please follow other related articles on the PHP Chinese website!

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