adgram1
asked on
preg_replace instead eregi_replace
Hi
I have this code
$main="we have {no} players ";
$no=3;
$template = eregi_replace("{no}", "$no", $main);
ECHO "$template";
// we have 3 players
How can i write it using preg_replace instead eregi_replace (for php6 use)
thnaks
Andreas
I have this code
$main="we have {no} players ";
$no=3;
$template = eregi_replace("{no}", "$no", $main);
ECHO "$template";
// we have 3 players
How can i write it using preg_replace instead eregi_replace (for php6 use)
thnaks
Andreas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually, sudhakarsp06's code is wrong.
curly braces are special characters which are using for repetition and it may cause unexpected results.
http://www.regular-expressions.info/repeat.html
You should escape them.
curly braces are special characters which are using for repetition and it may cause unexpected results.
http://www.regular-expressions.info/repeat.html
You should escape them.
ASKER
Both of solutions where right , i gave the points to first answer
Thanks all
Andreas
Thanks all
Andreas
@adgram1
Thanks for the points.
Thanks for the points.
$no=3;
$template = preg_replace("/{no}/", "$no", $main);
echo "$template";