php method to remove whitespace characters: first create a PHP sample file; then delete all whitespace characters in the string through the "preg_replace("/\s /", "", $var);" method Can.
Recommendation: "PHP Video Tutorial"
PHP Remove Whitespace Characters
Example 1:
<?php $var = " This is a beautiful day!"; // 删除字符串中的所有空白字符(不包括全角空格) $var1 = preg_replace("/\s+/", "", $var); echo $var1.'<br>'; ?>
Example 2:
<?php // 删除字符串中所有的字符(包括全角空格) $var = " This is a beautiful day!"; $var1 =preg_replace("/\s| /", "", $var); // 已经包含了全角空格 echo $var1.'<br>'; ?>
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!