Welcome to WebmasterWorld Guest from 22.214.171.124 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
preg replace problem compose
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.
You may need to add a $ to the pattern, so that it knows to stop: preg_replace([^a-zA-Z0-9$],"-",$string); compose
Thanks for reply. But it not works :(.
Try this (not tested, but similar to something I use): preg_replace("^([a-zA-Z0-9])$","-",$string); coopster
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: <pre> <?php $string = 'abcABC123-@#4abcABC123'; print "$string\n"; $updatedString = preg_replace("/[^a-zA-Z0-9]/","-",$string); print "$string\n"; print "$updatedString\n"; ?> </pre>