php method to delete spaces in a string: 1. Use str_ireplace() function, syntax "str_ireplace(' ', '', $str)"; 2. Use str_replace() function, syntax "str_replace( ' ', '', $str)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Method 1: Use str_ireplace() Function
<?php $str = 'hello world !'; $search = ' '; $replace = ''; echo str_ireplace($search, $replace, $str); ?>
Output:
helloworld!
Method 2: Use str_replace() function
<?php $str = 'hello world !'; $str = str_replace(' ', '', $str); echo $str; ?>
Output:
helloworld!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove spaces in string in php. For more information, please follow other related articles on the PHP Chinese website!