Remove Spaces in PHP Strings
Mon Oct 26 01:07:57 2009
I'm still very much at the beginning of learning PHP and while programming this blog, I came across a wonderful PHP function that can be used to remove/replace spaces (amongst other things) in strings. I know it will come in handy for someone. It's called str_replace(); The syntax is as follows:
str_replace(item to be replaced, item to replace with, string to commit this function);
<?php	
 
//creating a string held inside a variable.
$origString = "This is the original string.";
//display the string.
echo $origString;
//replace " " width "". In other words, replace spaces with no spaces.
$newString = str_replace (" ", "", $origString);
//display the new string.
echo $newString;
?>     	Tweet	← back












