Home > Article > Backend Development > How to remove whitespace characters in php
How to remove white characters in php
In php, you can use the function "preg_replace" to remove white characters. The function of this function executes a regular When using expression search and replacement, you need to pass in 3 parameters. The first parameter is the regular expression "/\s /", the second parameter is empty, and the third parameter is the string from which whitespace characters are to be removed. , and finally receive the return value.
Usage example:
<?php $var = " This is a beautiful day!"; // 删除字符串中的所有空白字符(不包括全角空格) $var = preg_replace("/\s+/", "", $var); echo $var; ?>
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to remove whitespace characters in php. For more information, please follow other related articles on the PHP Chinese website!