PHP preg_replace $1 without space
I have a problem with preg_replace and $1 + variable without a space
between $1 and the variable.
I have this code:
$replace_id = 5000;
$search = 1000;
$movies = '[1000,2000,2300,1234]';
$new_movies =
preg_replace('#(,|\[)'.$search.'(,|\])#Uis','$1'.$replace_id.'$2',$movies);
echo $new_movies;
The output:
000,2000,2300,1234]
But I want to have this output:
[5000,2000,2300,1234]
When I use the preg_replace with a space between $1 and $replace_id:
$new_movies = preg_replace('#(,|\[)'.$search.'(,|\])#Uis','$1
'.$replace_id.'$2',$movies);
It works perfect, but I need this without a space inside!
Do you have any idea?
Thanks!
No comments:
Post a Comment