背景(非常简化):我有一个在线商店和一个选择框。我有很多文章和很多选择框。因此,我必须使用 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"> [{ $listitem->oxorderarticles__oxartnum->value }]</td>
<td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff"> [{ $listitem->oxorderarticles__oxtitle->getRawValue()|oxtruncate:20:""|strip_tags }][{if $listitem->oxwrapping__oxname->value}] ([{$listitem->oxwrapping__oxname->value}]) [{/if}]</td>
<td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff"> [{ $listitem->oxorderarticles__oxselvariant->value }]</td>
[{if $edit->isNettoMode() }]
<td valign="top" class="edittext"> [{ $listitem->getNetPriceFormated() }] [{ $edit->oxorder__oxcurrency->value }]</td>
[{else}]
<td valign="top" class="edittext" style="background-color:#e2d9d9; border: 1px solid #fff"> [{ $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}]
, <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( "/<!--(.|\s)*?-->/" , "###" , $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/