web2000 Posted May 17, 2007 Share Posted May 17, 2007 Hello, I want to trim all white spaces our of a string and also any other characters other than numbers and letters. It is for a domain name script so it needs everything removed other than numbers and letters I have this so far but this only does white space?? $text = preg_replace('/\s+/', ' ', $text); Link to comment https://forums.phpfreaks.com/topic/51764-trim-white-spaces/ Share on other sites More sharing options...
hvle Posted May 17, 2007 Share Posted May 17, 2007 do you want to trim or to remove specific character from a string? Link to comment https://forums.phpfreaks.com/topic/51764-trim-white-spaces/#findComment-255039 Share on other sites More sharing options...
web2000 Posted May 17, 2007 Author Share Posted May 17, 2007 errmm well to totally remove everything other than numbers and text characters so 0-9 and a-z Link to comment https://forums.phpfreaks.com/topic/51764-trim-white-spaces/#findComment-255040 Share on other sites More sharing options...
cmgmyr Posted May 17, 2007 Share Posted May 17, 2007 Try this: <?php $text = "This is a test 1234"; echo preg_replace('/[^a-zA-Z0-9]/','',$text); ?> Link to comment https://forums.phpfreaks.com/topic/51764-trim-white-spaces/#findComment-255044 Share on other sites More sharing options...
hvle Posted May 17, 2007 Share Posted May 17, 2007 This also work, used the build-in alpha numeric char set ereg_replace("[^[:alnum:]]",'',$str); Link to comment https://forums.phpfreaks.com/topic/51764-trim-white-spaces/#findComment-255048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.