I have a PHP function to catch long URLs and trim them so they don't break my site's formatting. I have wordwrap catching sentences but I can't stop text like this:
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
How would I stop user input like that ?
The things I've tried work if there's dashes present (and I've tried ­
too in some functions) but none affect the above. It's for a forum and this is the last bit of user input I can't stop breaking my site ! Thanks for your help in advance.
Basically what you want to do is implement a Markov Chain or Bloom Filter to try and identify 'gibberish' as such.
Forget where I got this now, but I have used this small function:
echo contains_gibberish( "heiahihaiaheiah" );
This will allow you to flag input as potentially garbage, alternatives include wrapping the text etc.
Output:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Rather than trying to break the word in PHP, you can use CSS to style the page such that it breaks long words when they don't fit into the available space.
The CSS style for this is
word-wrap:break-word;
.Apply this to the element that contains the long text, and it will wrap long words when necessary.
Hope that helps.
wordwrap()
will break up long words if you includeTRUE
as the fourth parameter:This will insert a break at or before 30 characters.
TRUE
is required to force a break in long words. IfFALSE
(the default) is used, the lines are broken only on spaces.