Home>Article>Daily Programming> How to filter spaces in string in PHP

How to filter spaces in string in PHP

藏色散人
藏色散人 Original
2018-12-06 16:47:36 9564browse

PHP filtering string spaces is one of the common basic questions in the PHP interview process. It is also a basic PHP knowledge point that we need to master in our daily project development. PHP filtering string spaces is also very simple. You mainly need to understand the trim function in PHP.

How to filter spaces in string in PHP

Below we will introduce to you through a simple code example,How PHP filters spaces in strings.

The code for a string with spaces is as follows:

";

Here we can output the original length of this string:

How to filter spaces in string in PHP

Filter space operation, the code is as follows:


      

The result is as follows:

How to filter spaces in string in PHP

Main function:

trim() functionmeans removing blank characters or other predefined characters on both sides of the string.

Related functions:

ltrim() means removing blank characters or other predefined characters on the left side of the string.

rtrim() means removing whitespace characters or other predefined characters on the right side of the string.

This article is an introduction to how PHP filters spaces in strings. It is very simple and easy to understand. I hope it will be helpful to friends in need!

The above is the detailed content of How to filter spaces in string in PHP. 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