Link to home
Start Free TrialLog in
Avatar of adgram1
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
ASKER CERTIFIED SOLUTION
Avatar of Ovunc Tukenmez
Ovunc Tukenmez
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$main="we have {no} playeno ";  
$no=3;    
               

$template = preg_replace("/{no}/", "$no", $main);

echo  "$template";
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.
Avatar of adgram1
adgram1

ASKER

Both of solutions where right , i gave the points to first answer
Thanks all
Andreas
@adgram1
Thanks for the points.