Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
2  
what about just using css word-break: break-all;? –  Milo Nov 17 '12 at 4:24
add comment

1 Answer

Thank you Milo,

"word-break" alone wasn't enough as it's css3 only and not cross-browser.

But I found this:

.bloc_content{
    overflow:hidden; 
   -ms-word-break: break-all;
    word-break: break-all;
    word-break: break-word;
   -webkit-hyphens: auto;
   -moz-hyphens: auto;
    hyphens: auto;
}

It seems to to work in all cases I tested. Hopefully it would be cross-browser enough to solve the problem. Not sure if it would resist to old browsers though...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.