我在mysql
db中有以下代码,我需要更改json
代码。我试图找到一个解决方案,我可以删除<script>
标签以及它们之间的所有内容。然后,我可以使用CONCAT
添加更新的<script>
内容。
如何删除部分记录? RLIKE和REGEXP似乎没有做我需要的事情。
有什么建议吗?
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "Birlea Sophia Single Cream Metal Bed Frame",
"image": [
"http://www.myshop.co.uk/cache/images/products/50265_thumb.jpg",
"http://www.myshop.co.uk/cache/images/products/50265.jpg",
"http://www.myshop.co.uk/cache/images/products/50265_large.jpg"
],
"description": "The Birlea Sophia cream metal bed frame has classic styling with delightful heart details on the head and foot ends and a smooth cream finish.
This bed frame is sturdy in construction and has a sprung slatted base to give any style of mattress the ideal support it needs. The Sophia is also available in a pretty pink finish.
The Sophia from Birlea is a pretty girl's bed frame and perfect for brightening up any bedroom, so BUY NOW.
Please note: Bed frames are self assembly and priced without a mattress.",
"color": "Cream/Ivory",
"mpn": "SOPB3CRM",
"gtin14": "05060307681031",
"offers": {
"@type": "Offer",
"priceCurrency": "GBP",
"price": "84.97"
},
"brand": {
"@type": "Thing",
"name": "Birlea"}
}</script> <p style="text-align: justify">The Birlea Sophia cream metal bed frame has classic styling with delightful heart details on the head and foot ends and a smooth cream finish.</p>
<p style="text-align: justify">This bed frame is sturdy in construction and has a sprung slatted base to give any style of mattress the ideal support it needs. The Sophia is also available in a <a href="http://www.myshop.co.uk/Birlea-Sophia-Single-Pink-Metal-Bed-Frame-p1402.html">pretty pink finish</a>.</p>
<p style="text-align: justify">The Sophia from Birlea is a pretty girl's bed frame and perfect for brightening up any bedroom, so <strong><span style="color: #df0000">BUY NOW.</span></strong></p>
<p style="text-align: justify"><b style="text-align: start;">Please note: Bed frames are self assembly and priced without a mattress.</b></p>
答案 0 :(得分:1)
我建议你看一下UpdateXML MySQL函数(https://dev.mysql.com/doc/refman/5.7/en/xml-functions.html#function_updatexml)。
以下是基于您提供的内容的示例。
我将您的xml内容放在XML表的CONTENT列中:
mysqli_fetch_array($result, \MYSQLI_ASSOC)
mysqli_fetch_assoc($result)
然后我使用UpdateXML用空字符串替换每个匹配“// script”Xpath的标记:
mysql> select CONTENT from XML\G
*************************** 1. row ***************************
CONTENT: <script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": "Birlea Sophia Single Cream Metal Bed Frame",
"image": [
"http://www.myshop.co.uk/cache/images/products/50265_thumb.jpg",
"http://www.myshop.co.uk/cache/images/products/50265.jpg",
"http://www.myshop.co.uk/cache/images/products/50265_large.jpg"
],
"description": "The Birlea Sophia cream metal bed frame has classic styling with delightful heart details on the head and foot ends and a smooth cream finish.
This bed frame is sturdy in construction and has a sprung slatted base to give any style of mattress the ideal support it needs. The Sophia is also available in a pretty pink finish.
The Sophia from Birlea is a pretty girl's bed frame and perfect for brightening up any bedroom, so BUY NOW.
Please note: Bed frames are self assembly and priced without a mattress.",
"color": "Cream/Ivory",
"mpn": "SOPB3CRM",
"gtin14": "05060307681031",
"offers": {
"@type": "Offer",
"priceCurrency": "GBP",
"price": "84.97"
},
"brand": {
"@type": "Thing",
"name": "Birlea"}
}</script> <p style="text-align: justify">The Birlea Sophia cream metal bed frame has classic styling with delightful heart details on the head and foot ends and a smooth cream finish.</p>
<p style="text-align: justify">This bed frame is sturdy in construction and has a sprung slatted base to give any style of mattress the ideal support it needs. The Sophia is also available in a <a href="http://www.myshop.co.uk/Birlea-Sophia-Single-Pink-Metal-Bed-Frame-p1402.html">pretty pink finish</a>.</p>
<p style="text-align: justify">The Sophia from Birlea is a pretty girl's bed frame and perfect for brightening up any bedroom, so <strong><span style="color: #df0000">BUY NOW.</span></strong></p>
<p style="text-align: justify"><b style="text-align: start;">Please note: Bed frames are self assembly and priced without a mattress.</b></p>
1 row in set (0.00 sec)