【问题标题】:Showing Product Description as Category List Description - OpenCart [duplicate]将产品描述显示为类别列表描述 - OpenCart [重复]
【发布时间】:2012-07-11 04:47:12
【问题描述】:

可能重复:
Spliting Results of PHP Query into Columns

我有以下从数据库中提取描述的代码行,

我要做的是在描述中添加<br/>,这样它就不会显示为一长串数据。

mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..'

当前:

数据数据数据数据数据数据数据数据数据数据数据数据数据数据数据数据

必填:

数据数据

数据数据

数据数据

完整代码:

            $this->data['products'][] = array(
                'product_id'  => $result['product_id'],
                'thumb'       => $image,
                'name'        => $result['name'],
                'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
                'price'       => $price,
                'special'     => $special,
                'tax'         => $tax,
                'rating'      => $result['rating'],
                'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
                'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
            );

【问题讨论】:

    标签: php opencart


    【解决方案1】:
    <?php
    
    $text = 'Data Data Data Data Data';
    
    $data = explode(' ', $text);
    
    foreach($data as $key => $value) {
        if ($key % 2 == 0) {
            echo '<br />';
        }
        echo $value . ' ';
    }
    

    【讨论】:

    • 谢谢,我已经放了完整的代码,是否需要从当前数组中拆分出来?
    【解决方案2】:

    使用wordwrap() 可能更合适,例如

    $text = 'Data Data Data Data Data';
    echo wordwrap($text, 10, '<br />', true);
    

    结果:

    Data Data
    Data Data
    Data Data
    

    【讨论】:

    • 我将在上面的 mb_substr 字符串中哪里实现上述内容?
    • 在字符串上,例如mb_substr(wordwrap(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 10, '&lt;br /&gt;', true), 0, 100) . '..'
    • 嘿,它似乎无法正常工作:( d.pr/i/U0CG 10 太少了
    • 将数字增加到每行需要多少个字符,10 只是一个示例;)
    • 我有,但每一行没有相同数量的字符
    【解决方案3】:

    我已通过执行以下操作解决了此问题:

    编辑 -> catelog/view/theme/default/template/product/product.tpl

    在上面的 .tpl 文档中,我在数组中调整了 第 196 行

    发件人:

    'description' => mb_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..'
    

    收件人:

    'description' => strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'),'<p>'),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 2021-10-09
      • 2019-05-03
      • 2021-06-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多