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.
Jasminkumar Borad
I'm a full-stack developer, enterpreneur and owner of webstuffsolution.com. I live in india and i like to write tutorial and tips that can help to other user. I like to share various programming language tips and solution. I believe in hardworking and consistency.