In this program, we are removing the white spaces from the string for that we are using the built-in function str_replace().
For example, if the text is "Welcome to PHP learning platform" then the output will be "WelcometoPHPlearningplatform".
To remove the white space from the string we are using str_replace()
and replacing the white space with nothing by doing this the white space will be removed from the string.
Syntax of str_replace()
str_replace(find,replace,string,count)
Step 1: Assign the string into the variable string
Step 2: Print the value of the variable string as the String before removing the white spaces
Step 3: Remove the white space by using the built-in function to replace str_replace()
Step 4: Print the value of the variable string as the String after removing the white spaces
<?php
$string = "learne tutorials . com";
echo "String before removing the white spaces: $string \n";
$string = str_replace(' ', '', $string);
echo "String after removing the white spaces: $string";
?>
String before removing the white spaces: learne tutorials . com String after removing the white spaces: learnetutorials.com