yami007 Posted September 1, 2009 Share Posted September 1, 2009 when a user type a long word like ( helllllllllllllllllllllllllllllllllllllllllllllllllllllo ) or longer it may affect my layout. i wanna avoid it at any cost ^^ thanks.. Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/ Share on other sites More sharing options...
Zane Posted September 1, 2009 Share Posted September 1, 2009 so you want a particular character length instead of a traditional character length Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-909969 Share on other sites More sharing options...
yami007 Posted September 1, 2009 Author Share Posted September 1, 2009 so you want a particular character length instead of a traditional character length sorry, i dont quite understand !! Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-909970 Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 You could create a regex to break up these words but i feel this be down to your HTML/CSS ! here's a concept of adding a space after the 5th repeated letter $para = "hellllllllllllllllllllo"; echo preg_replace('/(\w{5})(\1)/im', '\1 \2', $para); //returns helllll llllllllll lllllo Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-909972 Share on other sites More sharing options...
ShaunO Posted September 1, 2009 Share Posted September 1, 2009 A client side solution would be to assign the overflow-x: scroll property to the container of the text and setting a fixed width but otherwise the regex solution above ^^ should cause the words to wrap properly. Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-909994 Share on other sites More sharing options...
ReKoNiZe Posted September 1, 2009 Share Posted September 1, 2009 Or maybe he wants like: if(strlen($variable) > 12) echo 'String is too long, try again'; else echo 'Your string is short enough, you may enter'; Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-910041 Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 /*No Comment*/ Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-910051 Share on other sites More sharing options...
yami007 Posted September 1, 2009 Author Share Posted September 1, 2009 You could create a regex to break up these words but i feel this be down to your HTML/CSS ! here's a concept of adding a space after the 5th repeated letter $para = "hellllllllllllllllllllo"; echo preg_replace('/(\w{5})(\1)/im', '\1 \2', $para); //returns helllll llllllllll lllllo can i do this for a text?? in textarea Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-910229 Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 of course but i would only use it for output, $para = $_POST['elementName']; in truth i would use CSS Quote Link to comment https://forums.phpfreaks.com/topic/172633-solved-how-can-i-avoid-long-words-on-string/#findComment-910237 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.