用于在表中强制换行的PHP或HTML/CSS解决方案
I have a table filled with user generated text. The text spans for as much as the TD allows, however if the input is a string made of a long string with no breaking chars (white space, dash etc) it messes up the table.
我有一个满是用户生成的文本的表。文本的跨度与TD所允许的一样大,但是,如果输入是一个由长字符串组成的字符串,没有中断字符(空格、破折号等),则会使表变得混乱。
e.g. ggggggggggggggggggggggggggggggggggggggggggggggggggggg
例如ggggggggggggggggggggggggggggggggggggggggggggggggggggg
How can I make it so that those strings wrap as well?
我怎么才能让这些字符串也被打包呢?
Thank you.
谢谢你!
2 个解决方案
#1
9
You can use CSS:
你可以使用CSS:
table {
table-layout: fixed;
width: 100%;
}
table td, table th {
word-wrap: break-word; /* Internet Explorer 5.5+, Chrome, Firefox 3+ */
overflow-wrap: break-word; /* CSS3 standard: Chrome & Opera 2013+ */
}
/* Use this if you also want to preserve multiple spaces in text */
table td, table th {
white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: pre-wrap; /* CSS3 */
}
Here is an example: http://www.jsfiddle.net/QPP8A/ (now out of date, sorry)
这里有一个例子:http://www.jsfiddle.net/QPP8A/(现在已经过时了,抱歉)
If you find this to hard to apply, you can use PHP's wordwrap function:
如果您觉得这个很难应用,可以使用PHP的wordwrap函数:
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
更多相关文章
- knitr html输出中的字符串太长
- 从数组中构建越来越长的字符串
- 如何解析命令行字符串来使用regex获取每个参数?
- php逐个汉字遍历字符串
- php 把驼峰样式的字符串转换成下划线样式的字符串
- 返回key包含此字符串的值
- 仅在两个字符串之间移除空白。
- 在PHP中写入xml时,从字符串中删除&
- 使用PHP捕获正则表达式的字符串的一部分?