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");

更多相关文章

  1. knitr html输出中的字符串太长
  2. 从数组中构建越来越长的字符串
  3. 如何解析命令行字符串来使用regex获取每个参数?
  4. php逐个汉字遍历字符串
  5. php 把驼峰样式的字符串转换成下划线样式的字符串
  6. 返回key包含此字符串的值
  7. 仅在两个字符串之间移除空白。
  8. 在PHP中写入xml时,从字符串中删除&
  9. 使用PHP捕获正则表达式的字符串的一部分?

随机推荐

  1. 应用CSS转换XML文档的示例介绍
  2. 利用xslt将xml解析成xhtml的代码示例
  3. 通过Spry将XML数据显示到HTML页教程
  4. 关于读大数据量的XML文件的读取问题
  5. 实现Asp与XML交互的实例解析
  6. XML SAX解析详解
  7. XML相关技术资料总结
  8. Android中的xml解析
  9. 五个XML技巧
  10. 怎样让Asp与XML交互