php - 将文本转换为评论

标签 php html mysql comments smarty

背景(非常简化):我有一个在线商店和一个选择框。我有很多文章和很多选择框。因此,我必须使用 php 将注释添加到选择框,以便它们在数据库中有所不同。

问题(也非常简单):当我加载数据集时(我希望我拼写正确),我显然得到了选择+评论。

问题(更简化):

我得到了这个:

<td>VariantXYZ <!-- randomID --></td>

显示如下(没有蓝色):

VariantXYZ <!-- randomID -->

问题:如何将评论转换为评论?^^

编辑:我之前也尝试过 preg_replace 方法,但它对我不起作用,因为我忘记了我使用 smarty ;-)

我的代码如下:

[{foreach from=$orderArticles item=listitem}]
            <tr>
                <td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff">[{ $listitem->oxorderarticles__oxamount->value }] * </td>
                <td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff">&nbsp;[{ $listitem->oxorderarticles__oxartnum->value }]</td>
                <td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff">&nbsp;[{ $listitem->oxorderarticles__oxtitle->getRawValue()|oxtruncate:20:""|strip_tags }][{if $listitem->oxwrapping__oxname->value}]&nbsp;([{$listitem->oxwrapping__oxname->value}])&nbsp;[{/if}]</td>
                <td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff">&nbsp;[{ $listitem->oxorderarticles__oxselvariant->value }]</td>

                [{if $edit->isNettoMode() }]
                    <td valign="top" class="edittext">&nbsp;&nbsp;[{ $listitem->getNetPriceFormated() }] [{ $edit->oxorder__oxcurrency->value }]</td>
                [{else}]
                    <td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff">&nbsp;&nbsp;[{ $listitem->getTotalBrutPriceFormated() }] [{ $edit->oxorder__oxcurrency->value }]</td>
                [{/if}]
                [{ if $listitem->getPersParams() }]
                <td valign="top" class="edittext">
                    [{foreach key=sVar from=$listitem->getPersParams() item=aParam name=persparams}]
                        &nbsp;&nbsp;,&nbsp;<em>
                            [{if $smarty.foreach.persparams.first && $smarty.foreach.persparams.last}]
                                [{ oxmultilang ident="GENERAL_LABEL" }]
                            [{else}]
                                [{$sVar}] :
                            [{/if}]
                            [{$aParam}]
                        </em>
                    [{/foreach}]
                </td>
                [{/if}]
            </tr>
            [{/foreach}]

我想在 $listitem->oxorderarticles__oxselvariant->value 上使用 preg_replace,我已经这样做了:

[{$listitem = preg_replace( "/&lt;!--(.|\s)*?--&gt;/" , "###" , $listitem )}]

但它会删除带有 $listitem 的所有字段。

我应该提到我首先使用 smarty。对此感到抱歉。

最佳答案

我认为这可能与字符串的编码有关。您可以在将其输出到页面之前尝试一下吗:

$text = html_entity_decode($text);

http://php.net/manual/en/function.html-entity-decode.php

这可能会有所帮助。但你真正需要做的是查看源代码,看看里面到底有什么。另一种选择可能是:

$text = stripslashes($text);

http://uk3.php.net/manual/en/function.stripslashes.php

我真的不知道你的具体问题是什么。我还在 Smarty 文档中找到了这一点:

http://www.smarty.net/docs/en/variable.escape.html.tpl

另一种改变字符编码方式的方法。您可以尝试:

{$variable nofilter} 

看看是否有帮助。但这是一个有多种可能原因的问题,因此没有保证。您需要按照数据一步步进行调试。

关于php - 将文本转换为评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26484015/

相关文章:

php - php5.3.0中sha256的使用方法

html - 为什么我的标题开始这么低?

php - SQL 没有获取第二行的 ID

php - Magento 文件夹更改

javascript - AJAX 数据未传入 PHP

php - 自定义PHP错误处理,也不会显示PHP错误

php - mysql获取选择数据以存储在数组中但我只得到1作为返回

html - Bootstrap 3 菜单断点更改但现在菜单没有折叠

javascript - 仅在页面初始加载时启动 Pace.js

mysql - 如何在 MySQL 中将一个数字与一个单词连接起来?