I want to prevent users from posting things like "aaaadfgdfgsdfgdaaaadsfgsdfgaaasdfgdfaaadfgsdfgaaaaaaaajahkjhkahkkjkjhaa..." which would not only be annoying but would certainly break the content div when the word is longer than the div itself.
I found a neat regex which solved the problem:
$thecontent = preg_replace('/\w{40}(?=\w)/', "$0-", get_the_content());
This would place hyphens inside any word having more than 40 characters in order to force a line-break if necessary and keep the layout unharmed.
The thing is I would like to apply this only when the word is plain text but certainly not when it's a url (or an email address perhaps).
Ultimately, a url like "http://www.aaaa.com/sdfsdfdfg/sdfsdsdfs/dsdsdfs.php?var1=dfsdfsdfvar2=sdfsdf&var3=dsfsfds" should remain as it is as I believe it's automatically taken care of by wordpress (I tried and created a long url and it displayed correctly in two lines so it seems to be ok).
With the regex here above, even the url is processed which is a problem.
How can I avoid to apply that regex to (email addresses and) standard transfer protocol urls such as http, https, ftp, ftps?
PS: I tried some client-side hyphenator plugins but they just don't fit my needs.
Thank you for your help.
word-break: break-all;? – Milo Nov 17 '12 at 4:24