Split long words in strings WITHOUT ruining HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Caliber
Forum Newbie
Posts: 5
Joined: Sat Feb 08, 2003 1:14 pm

Split long words in strings WITHOUT ruining HTML

Post by Caliber »

Lets say that I've got a string, $mystring, with lots of text, including a couple of very long words.
I want a function that splits all long words, so that there are no words larger than 40 characters, in the string.

BUT! I want everything that is between the < and > tags to stay unaffected by the function. So if I have a very long URL in an IMG src-tag or A href-tag, the URL may not be split.

Hope that you can help me.
Thanx in advance
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

What your probably looking for is some hyphenation... there is one script at hotscripts.com (http://www.hotscripts.com/Detailed/14316.html) - I personally haven't used it, but it might be worth a look. With some tweaking it might be able to do what you need.
Post Reply