views:

46

answers:

3

Hi!

My problem is that I have quite a small area (div or span), in which one to about five words are displayed. However, the area is too small for some words (for instance "muziekgeschiedenis" will surpass the area's bounds). Is there a way in PHP to wrap this word, but not solely based on number of characters? I can use wordwrap(), or just CSS properties for wordwrapping, but that may wrap this word into "muziekgeschiedeni-s", which is not wanted. It should break into for instance "muziekgeschiede-nis", based on syllables. Are there any PHP extensions that support word breaking/wrapping like this?

Thanks!

+2  A: 

this is called "hyphenation" and this is the first link that google gives on "php hyphenation"

http://yellowgreen.de/phphyphenator

hope this helps

stereofrog
Thanks, this looks good, I'll take a look at it.
Lex
On the page you referred to, there was a link to MoreCSS, I use that now. Thanks!
Lex
A: 

For PHP there is this PEAR Package TexHyphen, which uses the Tex algorithm to find syllables. It is alpha for six years and not maintained though, so @stereofrog's suggestion is probably a better bet.

An alternative to PHP would be Javascript. There is a Hyphenator lib at Google Code. Keep in mind that this approach requires the user to have JavaScript enabled though. Actually, phpHyphenator is a port of this lib.

Gordon
A: 

Here is a PHP based hyphenation library, and a port of this library to a WordPress plugin: wp-Typography.

kingjeffrey