Reputation: 6081
and it's driving me nuts. I tried everything. I have two strings.
The first one Allee 4
The second one 4
These are the regexxes I tried
$a = preg_replace ( "#\ \;#u", " ", $address[1]);
$a = preg_replace ( "#\ \;#", " ", $address[1]);
$a = preg_replace ( "# #u", " ", $address[1]);
$a = preg_replace ( "# #", " ", $address[1]);
None of them worked. The string always stayed 4
. Am I missing something?
Of course I already save the replacement into a variable...
Upvotes: 0
Views: 73
Reputation: 69259
I believe you need to use:
$address[$i] = preg_replace("/ /", "", $address[1]);
You need to delimit regexes with //
. Not sure if &
or ;
are escape characters, but I think not in this context.
Upvotes: 0
Reputation: 72855
Give this one a shot:
$address[1] = html_entity_decode($address[1]);
$address[1] = preg_replace("/\s/",'',$address[1]);
echo $address[1];
If it's working, do this to re-encode:
html_entities($address[1]);
Upvotes: 1
Reputation: 7257
preg_replace does not operate in place. It returns result so you must do:
$address[1] = preg_replace ( "#\ \;#u", " ", $address[1]);
$address[1] = preg_replace ( "#\ \;#", " ", $address[1]);
$address[1] = preg_replace ( "# #u", " ", $address[1]);
$address[1] = preg_replace ( "# #", " ", $address[1]);
Upvotes: 0