在 PHP 中没有任何可辨别的断点的情况下分解一行文本 [英] Break up one line of text without any discernible break points in PHP

查看:42
本文介绍了在 PHP 中没有任何可辨别的断点的情况下分解一行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PHP 函数来捕获长 URL 并修剪它们,这样它们就不会破坏我网站的格式.我有自动换行捕捉句子,但我无法停止这样的文本:

'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

我如何停止这样的用户输入?

如果存在破折号,我尝试过的事情就可以工作(并且我在某些功能中也尝试过 ­ ),但没有影响上述内容.这是一个论坛,这是用户输入的最后一点我无法停止破坏我的网站!提前感谢您的帮助.

解决方案

wordwrap() 如果你包含 TRUE 作为第四个参数,将会分解长词:

wordwrap( $very_long_string, 30, '<br/>', TRUE );

这将在 30 个字符处或之前插入一个中断.TRUE 需要强制中断长单词.如果使用 FALSE(默认值),则仅在空格处换行.

I have a PHP function to catch long URLs and trim them so they don't break my site's formatting. I have wordwrap catching sentences but I can't stop text like this:

'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

How would I stop user input like that ?

The things I've tried work if there's dashes present (and I've tried &shy; too in some functions) but none affect the above. It's for a forum and this is the last bit of user input I can't stop breaking my site ! Thanks for your help in advance.

解决方案

wordwrap() will break up long words if you include TRUE as the fourth parameter:

wordwrap( $very_long_string, 30, '<br />', TRUE );

This will insert a break at or before 30 characters. TRUE is required to force a break in long words. If FALSE (the default) is used, the lines are broken only on spaces.

这篇关于在 PHP 中没有任何可辨别的断点的情况下分解一行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆