How to remove spaces around values ​​in php

WBOY
Release: 2023-03-15 09:40:01
Original
2312 people have browsed it

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)
Copy after login

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));
?>
Copy after login

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!

Related labels:
php
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