json表数据如何限制td的长度?

时间:2015-11-28 16:15:55

标签: php mysql json codeigniter

我编辑了这个表,我用data.json文件下载了它,并让它通过foreach从数据库中获取数据

我正在使用Codeigniter 3

这是表格代码

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <table data-toggle="table" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc">
                    <thead>
                    <tr>
                        <th data-field="state" data-checkbox="true" >Post ID</th>
                        <th data-field="id" data-sortable="true">Post ID</th>
                        <th data-field="username"  data-sortable="true">Poster Author</th>
                        <th data-field="post" data-sortable="true">Post</th>
                        <th data-field="tid" data-sortable="true">Topic ID</th>
                        <th data-field="pdate" data-sortable="true">Post Date</th>
                    </tr>
                    </thead>
                    <tbody>
                        <?php
                        foreach ($posts as $post) {
                        echo '
                        <tr>
                        <td>'.$post->pid.'</td>
                        <td>'.$post->pid.'</td>
                        <td>'.$post->author_name.'</td>
                        <td>'.$post->post.'</td>
                        <td>'.$post->topic_id.'</td>
                        <td>'.unix_to_human($post->post_date).'</td>
                        </tr>';
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div><!--/.row-->  

我的问题是我想在post td

中限制最大长度
<td>'.$post->post.'</td>

有可能成功吗?

2 个答案:

答案 0 :(得分:1)

加载文本助手,而不是使用character_limiter($str[, $n = 500[, $end_char = '&#8230;']]),如:

$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
// Returns:  Here is a nice text string

或在你的情况下:

character_limiter($post->post, 100, '&#8230;');// You should set appropriate length

Docs

答案 1 :(得分:0)

在`related

中添加内联样式(或设置类stlyle并添加此类)
  <th style="maxwidth: 100px;"  data-field= .........>