【问题标题】:MySQL Update Query to remove specific Html tag from all the "description" fieldsMySQL 更新查询以从所有“描述”字段中删除特定的 Html 标记
【发布时间】:2016-05-24 06:22:01
【问题描述】:

我有一个 Magento 网站,其中每个产品的描述字段中都有一个锚标记,例如 <a href="link">Content</a>

现在我想删除这个锚标签以及它在标签内的内容,但保持其余描述不变。

现在的示例描述如下:

<ul>
    <li>Cylinder head has been assembled to OEM specifications with using all new components like Cam shaft, valves and/or springs, buckets, shims etc. where applicable.</li>
    <li>
        <a href="http://sampledomain.com/media/wysiwyg/folder/file.pdf">All heads we supply pass through 24 points of quality check program.</a>
    </li>
    <li>Warranty: 1 year or 20,000 Kms factory warranty.</li>
    <li>
        <b>Kit Includes:</b>
    </li>
    <li>Fully assembled cylinder head</li>
    <li>VRS (Vehicle regrind set)</li>
    <li>Head gaskets (thickest grade)</li>
    <li>Head bolts</li>
    <li>Warranty card</li>
</ul>

现在我希望它显示如下:

<ul>
    <li>Cylinder head has been assembled to OEM specifications with using all new components like Cam shaft, valves and/or springs, buckets, shims etc. where applicable.</li>
    <li>
    </li>
    <li>Warranty: 1 year or 20,000 Kms factory warranty.</li>
    <li>
        <b>Kit Includes:</b>
    </li>
    <li>Fully assembled cylinder head</li>
    <li>VRS (Vehicle regrind set)</li>
    <li>Head gaskets (thickest grade)</li>
    <li>Head bolts</li>
    <li>Warranty card</li>
</ul>

如何使用更新查询来做到这一点?

【问题讨论】:

  • 每个产品只包含一个锚标签还是多个?
  • 展示一个真实的样本和你需要的结果..
  • 每个产品描述只有一个锚标签。更新我的问题以添加描述。
  • 有些任务最好留给应用程序代码,而不是 SQL。

标签: html mysql sql regex magento


【解决方案1】:

这将完成工作..!

UPDATE your_table_name  
set description = 
concat
(
substring_index(description, '<a',1), 
substring_index(description, '</a>',-1)
);

【讨论】:

  • 但是不同的产品有不同的描述,这就是为什么我认为正则表达式会更好。
  • 你的回答对选择记录有好处,你也可以添加查询来更新这个吗?
猜你喜欢
  • 2014-03-03
  • 2013-07-16
  • 2011-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多