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? 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 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 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); 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, 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; Link to comment https://forums.phpfreaks.com/topic/129173-clean-string/#findComment-669744 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.