Fog Juice Posted February 20, 2008 Share Posted February 20, 2008 Hey, How can I remove every character from a string other than 0 to 9? Thanks, Chris Link to comment https://forums.phpfreaks.com/topic/92110-how-to-removing-illegal-characters/ Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 <?php $string = "I have values other then 0 45 7 and 432"; $string = preg_replace('/\D/','',$string); echo $string; ?> output: 0457432 Link to comment https://forums.phpfreaks.com/topic/92110-how-to-removing-illegal-characters/#findComment-471696 Share on other sites More sharing options...
effigy Posted February 20, 2008 Share Posted February 20, 2008 <script type="text/javascript"> var re = /\D+/g; var str = '*+a1b2c3d4e5f6-%'; alert(str.replace(re, '')); </script> Link to comment https://forums.phpfreaks.com/topic/92110-how-to-removing-illegal-characters/#findComment-471699 Share on other sites More sharing options...
Fog Juice Posted February 20, 2008 Author Share Posted February 20, 2008 <?php $string = "I have values other then 0 45 7 and 432"; $string = preg_replace('/\D/','',$string); echo $string; ?> output: 0457432 Considering this is the javascript part of phpfreaks.com, I was hoping to get a response with javascript in it lol Link to comment https://forums.phpfreaks.com/topic/92110-how-to-removing-illegal-characters/#findComment-471705 Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 Yeah...I was watching all the forums and missed which one this was actually in. And I know JS too...if only I read more carefully Link to comment https://forums.phpfreaks.com/topic/92110-how-to-removing-illegal-characters/#findComment-471706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.