Email: b4borad74@gmail.com Contact: +91 9724412437

Remove white space from string in PHP?
ByJasminkumar Borad
- On
- InPHP
In this tutorial explain multiple example of remove white spece from string in php.you will learn how to remove white space from string in php. you can understand a concept of remove space from string in php.
You can use multiple function of remove space from string in php.you can use str_replace() and trim() function will help to replace space that way remove space in string. let’s see below example.
1. Remove white space from string in php using str_replace() function
Example 1 :
<?php
$old_string = " you can doing well ";
/* remove space from string in php */
$new_string = str_replace(' ','',$old_string);
echo $new_string;
?>
Output:
you can doing well
2. Remove white space from string in PHP using trim() function
In this given example, you have removed the space from the given string the trim() function.
Example 2:
<?php
$old_string = " You can doing well ";
/* remove space from string in PHP */
$new_string = trim($old_string);
echo $new_string;
?>
Output:
You can doing well
I hope this tutorial help you.