我需要使用ajax输出几行转义的html,其中的对象由smarty生成。 但是,即使我同时使用nl2br和
,我仍然会收到意外的令牌|regex_replace:'/[\r\n]/' : '<br/>'.
这是一个麻烦的代码:
"value": "<div class="ps-header-links"><br/> <br/> <ul><br/> <li><a href="http://prestashop.com" title="some title"><span class="icon-small helpicon"></span>English</a></li><br/> <li><a href="dsjfsiodf" title="link2title"><span class="icon-small helpicon"></span>Link 2</a></li><br/> </ul> <br/> </div>",
以下是我在smarty模板上使用的内容:
"value": "{$data.value|addslashes|regex_replace:'/[\r\n]/' : '<br/>'}",
知道我做错了什么?原始的html(使用htmlspecialchars进行转义,因为我只需要一个可视化表示):
: <div class="ps-header-links">
<ul>
<li><a href="http://prestashop.com" title="some title"><span class="icon-small helpicon"></span>English</a></li>
<li><a href="dsjfsiodf" title="link2title"><span class="icon-small helpicon"></span>Link 2</a></li>
</ul>
</div>
完整错误
textStatus: 'parsererror'
errorThrown: 'SyntaxError: Unexpected token '
responseText:
{
"products": [
{
"id": 1,
"link": "http://localhost/presta156/index.php? id_product=1&controller=product&id_lang=1#/color-black/disk_space-16gb",
"quantity": 4,
"priceByLine": "765,04 €",
"name": "iPod Nano",
"price": "765,04 €",
"price_float": "632.28",
"idCombination": 18,
"idAddressDelivery": 2,
"is_gift" : 0,
"hasAttributes": true,
"attributes": "Black, 16GB",
"hasCustomizedDatas": true,
"customizedDatas":[
{
"customizationId": 19,
"quantity": "1",
"datas": [
{
"type": "1",
"datas":
[
{
"index": 0,
"value": "<div class="ps-header-links"><br/> <br/> <ul><br/> <li><a href="http://prestashop.com" title="some title"><span class="icon-small helpicon"></span>English</a></li><br/> <li><a href="dsjfsiodf" title="link2title"><span class="icon-small helpicon"></span>Link 2</a></li><br/> </ul> <br/> </div>",
"truncatedValue": "<div..."
} ]
} ]
} ]
}],
"discounts": [
],
"shippingCost": "2,42 €",
"shippingCostFloat": "2.42",
"wrappingCost": "0,00 €",
"nbTotalProducts": "4",
"total": "767,46 €",
"productTotal": "765,04 €",
"hasError" : false
}
更多信息: 似乎只有当html缩进时才会出现错误。单个空格是可以的,但制表符会导致问题。我有什么方法可以让他们脱颖而出吗?我试过{strip},替换'':''但它们不起作用!
修复:我使用| regex_replace转发标签:“/ [\ t] /”:“”