背景(非常简化):我有一个联机商店和一个选择框。我收到了许多文章和许多选择框。因此,我不得不用php将注释添加到选择框中,这样它们在DB中就不同了。
问题(也非常简化):当我加载数据集时(我希望我拼写正确),我显然得到了选择+注释。
问题(更简化):
我得到了这个:
<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->oxoderarticles__oxselvariant->值上使用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}
看看这是否有帮助。但这是一个有很多可能原因的问题,所以没有garantee。您需要一步一步地按照数据进行调试。