|preg replace problem|
| 9:53 am on Aug 26, 2006 (gmt 0)|
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.
| 11:55 am on Aug 26, 2006 (gmt 0)|
You may need to add a $ to the pattern, so that it knows to stop:
| 12:40 pm on Aug 26, 2006 (gmt 0)|
Thanks for reply. But it not works :(.
| 12:53 pm on Aug 26, 2006 (gmt 0)|
Try this (not tested, but similar to something I use):
| 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:
$string = 'abcABC123-@#4abcABC123';
$updatedString = preg_replace("/[^a-zA-Z0-9]/","-",$string);