根据语言使用 php 换行文本
我的问题是我有一个很小的区域(div 或 span),其中显示一到五个单词。但是,该区域对于某些单词来说太小(例如“muziekgeschiedenis”将超出该区域的边界)。 PHP 中有没有一种方法可以包装这个单词,但不仅仅基于字符数?我可以使用 wordwrap() 或仅使用 CSS 属性进行自动换行,但这可能会将这个单词包装成“muziekgeschiedeni-s”,这是不需要的。例如,它应该根据音节分解为“muziekgeschiede-nis”。有没有 PHP 扩展支持像这样的断字/换行?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这称为“连字符”,这是 google 提供的关于“php 连字符”的第一个链接
http://yellowgreen.de/ phphyphenator
希望这有帮助
this is called "hyphenation" and this is the first link that google gives on "php hyphenation"
http://yellowgreen.de/phphyphenator
hope this helps
这是一个基于 PHP 的连字符库,以及该库到 WordPress 插件的端口: wp-Typography。
Here is a PHP based hyphenation library, and a port of this library to a WordPress plugin: wp-Typography.
对于 PHP,有这个 PEAR 包 TexHyphen,它使用 Tex 算法来查找音节。它已经是 alpha 六年了,但没有维护,所以 user187291的建议可能是一个更好的选择。
PHP 的替代方案是 Javascript。 Google 代码中有一个 Hyphenator 库。请记住,这种方法需要用户启用 JavaScript。实际上, phpHyphenator 是这个库的一个端口。
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 user187291'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.
还有 TeX-Hyphenation 算法的此端口。
There is also this port of the TeX-Hyphenation Algorithm.