Kryptix Posted January 8, 2010 Share Posted January 8, 2010 Some people sign up with their name as "SPACE HERE" and have like 10 spaces in-between each word, I need it so they can only have one space at a time. How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/187657-spaces/ Share on other sites More sharing options...
n00bert Posted January 8, 2010 Share Posted January 8, 2010 You could do something like this that I found using google. <? $str = "This is just some text"; // use two spaces for the seperator while (sizeof ($array=explode (" ",$str)) != 1) { // use one space for the glue $str = implode (" ",$array); } echo $str; ?> hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/187657-spaces/#findComment-990727 Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 $username = preg_replace('%\s{2,}%', ' ', $username); Quote Link to comment https://forums.phpfreaks.com/topic/187657-spaces/#findComment-990734 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.