Home  >  Article  >  Backend Development  >  How to remove spaces around values ​​in php

How to remove spaces around values ​​in php

WBOY
WBOYOriginal
2022-02-11 15:46:502318browse

In PHP, you can use the trim() function to remove spaces around a value. This function is used to remove whitespace characters or other predefined characters on both sides of a string. The syntax is "trim(string,charlist) ".

How to remove spaces around values ​​in php

The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

How to remove the spaces around the numerical value in php

trim() function removes whitespace characters or other predefined characters on both sides of a string.

Related functions:

  • ltrim() - Removes whitespace characters or other predefined characters on the left side of a string.

  • rtrim() - Removes whitespace characters or other predefined characters on the right side of a string.

Syntax

trim(string,charlist)

Parameter Description

string Required. Specifies the string to check.

charlist Optional. Specifies which characters are removed from a string. If this parameter is omitted, all the following characters are removed:

  • "\0" - NULL

  • "\t" - tab character

  • "\n" - Line feed

  • "\x0B" - Vertical tab character

  • "\r" - Enter

  • " " - Space

The example is as follows:

<?php
$str = " 123456789 ";
var_dump($str);
echo "<br>";
var_dump(trim($str));
?>

Output result:

How to remove spaces around values ​​in php

Recommended study: "PHP Video Tutorial"

The above is the detailed content of How to remove spaces around values ​​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