根据语言使用 php 换行文本

发布于 2024-08-20 17:49:09 字数 273 浏览 3 评论 0原文

我的问题是我有一个很小的区域(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

oО清风挽发oО 2024-08-27 17:49:09

这称为“连字符”,这是 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

下雨或天晴 2024-08-27 17:49:09

这是一个基于 PHP 的连字符库,以及该库到 WordPress 插件的端口: wp-Typography

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

秋凉 2024-08-27 17:49:09

对于 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.

老子叫无熙 2024-08-27 17:49:09

还有 TeX-Hyphenation 算法的此端口

There is also this port of the TeX-Hyphenation Algorithm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文