I have a php string that outputs like this:
San Jose, California
I need the php string to output like this:
SanJose, Caliornia
I've been playing around with str_replace but not having much luck.
Any help would be appreciated!
I have a php string that outputs like this:
San Jose, California
I need the php string to output like this:
SanJose, Caliornia
I've been playing around with str_replace but not having much luck.
Any help would be appreciated!
Update: first explode with
$string = explode(",",$string);
then do for all value of $string ( in foreach for example )
For just spaces, use str_replace:
$string = str_replace(' ', '', $string);
For all whitespace, use preg_replace:
$string = preg_replace('/\s+/', '', $string);
look at here How to strip all spaces out of a string in php?
Don't use regulars expressions, it is overkill (slower). Use the count parameter of strreplace:
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
From PHP manual:
count
If passed, this will be set to the number of replacements performed.
$str = "San Jose, California";
$result = str_replace(" ", "", $str, 1);
Fatal error: Only variables can be passed by reference. 4th parameter has to be a variable that will be set by str_replace to number of replacements it performed.