regex - 如何在列表中仅保留 $product.description_short 的第一段?
问题描述
我只想在类别中保留产品描述的第一段。
例子:<p>This is a pretty good description.</p><p>The rest of the description, even if it's cool to I don't want it.</p>
至 :<p>This is a pretty good description.</p>
这是 product-list.tpl Prestashop (1.6) 中的默认代码:
<p class="product-desc" itemprop="description">
{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
</p>
这是我在 product-list.tpl Prestashop (1.6) 中尝试的默认代码:
<p class="product-desc" itemprop="description">
{assign var $newdescription = $product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}
{preg_replace('(?<=<\/p>)\s+<p>.*','',$newdescription)}
</p>
解决方案
{$_shorten = explode('</p>', $product.description_short)}
// with valid html tags
{$_shorten.0|cat:'</p>'}
// or if you want to strip tags:
{$_shorten.0|strip_tags}
推荐阅读
- sql - 如何显示员工表中的姓氏包含“a”或“o”或“e”字母?
- python - Django,智能选择,链式选择在 html 中不起作用
- azure - Azure TLS 证书更改
- android - 离子应用谷歌地图显示 - 移动设备位置问题
- javascript - 反应自动完成下拉位置按下其他输入元素
- javascript - ChartJS 删除图表中的数字
- android - 如何删除特定符号之前的字符
- sql-server - 在 SQL Server 中使用一行中的子标签查询 XML
- javascript - Moment js以分钟为单位比较差异
- python - Pandas groupby 无论符号如何都能获得最大值