I want to replace all character other then alphanumeric to "-", to get this output i wrote this expression but it not works, please check it.
preg_replace([^a-zA-Z0-9],"-",$string);
Please help.
Vineet
barns101
11:55 am on Aug 26, 2006 (gmt 0)
You may need to add a $ to the pattern, so that it knows to stop:
preg_replace([^a-zA-Z0-9$],"-",$string);
compose
12:40 pm on Aug 26, 2006 (gmt 0)
Hello,
Thanks for reply. But it not works :(.
Vineet
barns101
12:53 pm on Aug 26, 2006 (gmt 0)
Try this (not tested, but similar to something I use):
preg_replace("^([a-zA-Z0-9])$","-",$string);
coopster
1:49 pm on Aug 26, 2006 (gmt 0)
compose, your original pattern would have worked but you need to supply delimiters [php.net]. Also remember that the original string remains the same, you need to assign the replaced value to either the original variable or a new variable: