去除字符串到的空格有多种方法,下面介绍两种给大家:
使用 str_replace :
1 2 3 |
<?php $string = str_replace(' ', '', $string); ?> |
使用 preg_replace :
1 2 3 |
<?php $string = preg_replace('/\s+/', '', $string); ?> |
走走停停,看日出!
去除字符串到的空格有多种方法,下面介绍两种给大家:
使用 str_replace :
1 2 3 |
<?php $string = str_replace(' ', '', $string); ?> |
使用 preg_replace :
1 2 3 |
<?php $string = preg_replace('/\s+/', '', $string); ?> |