ballhogjoni Posted April 1, 2008 Share Posted April 1, 2008 How do i trim all the characters except for numbers? I assume I use the trim function. Ex: trim($string, "a-z,~!@#$%^&*()_+`[]{};':"<>?,./|\"); Am I missing something? Link to comment https://forums.phpfreaks.com/topic/99039-trim-question/ Share on other sites More sharing options...
Caesar Posted April 1, 2008 Share Posted April 1, 2008 <?php $str = 'This is a string containing an account#455000455'; $clean = preg_replace('/[^0-9]+/','',$str); ?> Link to comment https://forums.phpfreaks.com/topic/99039-trim-question/#findComment-506770 Share on other sites More sharing options...
ballhogjoni Posted April 1, 2008 Author Share Posted April 1, 2008 thanks, what if I just want the 2 letters FC to be able to show and not be trimmed? How would I do that using your example? Link to comment https://forums.phpfreaks.com/topic/99039-trim-question/#findComment-506780 Share on other sites More sharing options...
Caesar Posted April 1, 2008 Share Posted April 1, 2008 <?php $clean = preg_replace('/[^FC0-9]+/','',$str); ?> ...Would allow both numbers and 'F' and 'C' Link to comment https://forums.phpfreaks.com/topic/99039-trim-question/#findComment-506796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.