vbnullchar Posted October 20, 2008 Share Posted October 20, 2008 i want a string to be free of non alpha-num chars except dash.. how can i do this? Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/ Share on other sites More sharing options...
ghostdog74 Posted October 20, 2008 Share Posted October 20, 2008 how does your string looks like Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669692 Share on other sites More sharing options...
vbnullchar Posted October 20, 2008 Author Share Posted October 20, 2008 10$.2&31.1!2_32.123(as dfa).jpg Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669702 Share on other sites More sharing options...
ghostdog74 Posted October 20, 2008 Share Posted October 20, 2008 echo preg_replace("/[^-a-zA-Z0-9]+/","",$s); Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669713 Share on other sites More sharing options...
vbnullchar Posted October 20, 2008 Author Share Posted October 20, 2008 thanks, Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669739 Share on other sites More sharing options...
nrg_alpha Posted October 20, 2008 Share Posted October 20, 2008 You can simply the pattern as such: $str = '10$.2&31.1!2_32.123(as dfa).jpg'; $str = preg_replace('#[^a-z0-9-]#i', '', $str); echo $str; Quote Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.