编辑1:我试图使用下面的查询来获取,但问题是结束div不是在起始点之后发生的,即
select ID, post_title, substr(post_content,instr(post_content,'<div style="position:absolute') + 0, instr(post_content,'</div>')) as temp from wp_posts where post_content LIKE '%mySpamFilter Text%' LIMIT 10
我的一个博客遭到了垃圾邮件发送者的攻击,我有大约100多个帖子,这些帖子有垃圾邮件发送者融合的不需要的链接或邮件。我想知道如何替换两个字符串之间的字符串。
Start string = '<div style="position:absolute;'
End String = '</div>' (This End div should be the first end div after the above Start string)
我尝试了Stack溢出时可用的所有选项但到目前为止没有运气。请建议最好的方法继续。下面是来自wp_posts表的帖子之一的post_content列的内容 你可以在Paneer这个词之后看到div类之间有很多垃圾邮件。我想从我的数据库中删除它。我不知道我是如何成为这次袭击的受害者,但现在我只想删除这些。
<p>Hey Foodies,</p>
<p>Biryani, the pride of Hyderabad, is definitely one dish which everyone knows to cook in their very own ways and styles. Biryani is one such thing which totally distinguishes itself with the plain rice we eat daily and the regular pulao. Biryani is the BIRYANI. So, lets look into the detailed procedure of the much loved Hyderabadi delicacy, the vegetarian version. Oh yes, this is the Hyderabadi Dum Veg Biryani!</p>
<p>This recipe would take 380-400 grams of uncooked Basmati rice which would serve 6.</p>
<div class="easyrecipe">
<link itemprop="image" href="http://mywebsite.in/wp-content/uploads/2013/09/Biryani-300x225.jpg">
<div class="item ERName">Hyderabadi Veg Dum Biryani</div>
<div class="ERClear"></div>
<div class="ERHead"><span class="xlate">Recipe Type</span>: <span class="type">Main Course</span></div>
<div class="ERHead">Cuisine: <span class="cuisine">Indian</span></div>
<div class="ERHead">Prep time: <time itemprop="prepTime" datetime="PT30M">30 mins</time></div>
<div class="ERHead">Cook time: <time itemprop="cookTime" datetime="PT1H15M">1 hour 15 mins</time></div>
<div class="ERHead">Total time: <time itemprop="totalTime" datetime="PT1H45M">1 hour 45 mins</time></div>
<div class="ERHead">Serves: <span class="yield">6</span></div>
<div class="ERIngredients">
<div class="ERIngredientsHeader">Ingredients</div>
<ul class="ingredients">
<li class="ingredient">For Vegetables: Carrot - 1 medium</li>
<li class="ingredient">Potatoes - 1 medium</li>
<li class="ingredient">Paneer ***<div style="position:absolute; left:-3905px; top:-3984px;">Gloves fast it <a href="http://www.goprorestoration.com/natural-viagra-foods">natural viagra foods</a> recently! Like as <a href="http://www.backrentals.com/shap/daily-cialis.html">daily cialis</a> the purchase 1 pad <a href="http://www.vermontvocals.org/buy-online-cialis.php">generic viagra cheap</a> and matte easy <a href="http://www.teddyromano.com/blue-pills/">blue pills</a> me many. Content but <a href="http://augustasapartments.com/qhio/10-mg-cialis">10 mg cialis</a> the as the helps Amazon <a href="http://www.mordellgardens.com/saha/cheap-viagra-canada.html">http://www.mordellgardens.com/saha/cheap-viagra-canada.html</a> . And baths etc would. I've <a href="http://www.teddyromano.com/brand-cialis/">brand cialis</a> Appears dollars hands still <a href="http://www.backrentals.com/shap/generic-cialis-europe.html">shop</a> October a smell <a href="http://www.hilobereans.com/buy-real-viagra/">http://www.hilobereans.com/buy-real-viagra/</a> in have. Of better <a href="http://www.creativetours-morocco.com/fers/herbal-viagra-australia.html">cheap generic cialis</a> it smelled to and <a rel="nofollow" href="http://www.goprorestoration.com/best-price-viagra">best price viagra</a> t customer anything been <a href="http://www.mordellgardens.com/saha/viagra-online-reviews.html">viagra online reviews</a> 5 supply time <a href="http://www.hilobereans.com/viagra-canada-pharmacy/">"here"</a> the product what <a href="http://www.vermontvocals.org/ed-supplements.php">buy levitra</a> biological by cream!</div>*** - 1/2 cup</li>
<li class="ingredient">Cauliflower - 1/2 cup</li>
<li class="ingredient">Green peas - 1 tbsp.</li>
<li class="ingredient">Yogurt - 1/2 cup</li>
<li class="ingredient">Mint - 1 tbsp.</li>
<li class="ingredient">Coriander - 1 tbsp.</li>
<li class="ingredient">Ginger-Garlic paste - 1 tsp.</li>
<li class="ingredient">Green chili - 4 to 5</li>
<li class="ingredient">Oil - 2 tbsp</li>
<li class="ingredient">Salt - As per taste</li>
<li class="ingredient">Biryani Masala - 1 and 1/2 tbsp.</li>
<li class="ingredient">Red Chili Powder - 1/2 tsp.</li>
<li class="ingredient">Garam Masala Powder - 1/4 tsp.</li>
<li class="ingredient">Whole Garam Masala - Custom or readymade</li>
<li class="ingredient">For Rice: Basmati Rice(soaked for 1 hour) - 380 gms</li>
<li class="ingredient">Water - 6-8 cups</li>
<li class="ingredient">Oil - 1-2 Tbsp.</li>
<li class="ingredient">Whole Garam masala - Custom or readymade</li>
<li class="ingredient">Salt - 3 Tsp.</li>
<li class="ingredient">For Dum(Bringing together): Yogurt - 1/2 cup</li>
<li class="ingredient">Saffron strands - dipped in milk, a few</li>
<li class="ingredient">Chopped Nuts - As desired</li>
<li class="ingredient">Mint and Coriander - two handfuls</li>
<li class="ingredient">Fried onions - two handfuls</li>
<li class="ingredient">Green chili - 4-5 slits</li>
<li class="ingredient">Water - 1/4 cup</li>
</ul>
</div>
<div class="ERInstructions">
<div class="ERInstructionsHeader">Instructions</div>
<div class="instructions">
<ol>
<li class="instruction">For Veggies: In a kadhai add oil. Now add whole garam masala, ginger-garlic paste. Saute for a minute. Now add carrot, potatoes, cauliflower, peas and salt. Saute until they are lightly cooked.</li>
<li class="instruction">After the veggies are a bit cooked, add in biryani masala, red chili powder, garam masala powder and gradually add yogurt stirring well to prevent curdling of curd.</li>
<li class="instruction">Now add mint, coriander, paneer. Cook until the moisture gets dried out which was caused due to adding yogurt. This would take approx 5 minutes. Veggies should not be cooked completely as we will dum it later on. It should 70% cooked.</li>
<li class="instruction">After the moisture is dried, add some fried onions and transfer to a bowl.</li>
<li class="instruction">For Rice: Boil water. Add oil, whole garam masala, salt. Boil until roaring boil. Add the soaked rice. In about 3-4 minutes in high flame rice will be 70% done. Test by eating some if it has a bite but its tastes like cooked or press between ur fingers. If breaks into 2 parts its ready. Strain it and spread on a big plate.</li>
<li class="instruction">For Dum: Take a cooker, add half of the vegetables, yogurt, green chilli, a pinch of salt and some nuts. Let it heat. Now add a handful of mint coriander. Now top it off with a good layer of rice.</li>
<li class="instruction">Next add the remaining vegetables, remaining mint-coriander(leave 1 tsp. for top), fried onions and the rice. Spread the rice and add the saffron mixture with a bit of mint-coriander, fried onion.</li>
<li class="instruction">Now sprinkle 1/4 cup of water over it, Cover and cook for 2 minutes in lowest flame.</li>
<li class="instruction">Transfer the cooker to a big pot with some water. This water bath prevents the dum to get burnt.. In about 30-35 minutes the Biryani is ready to make you dig into it.</li>
</ol>
</div>
</div>
<div class="ERNutrition"></div>
<div>
<div class="ERNotesHeader">Notes</div>
<div class="ERNotes">Cut vegetables in a uniform size.[br]Veggies are less, but the rice is used more for Biryanis.[br]You could use raw chopped nuts or saute them in oil and add.[br]Make sure to soak rice for atleast 1 hour.</div>
</div>
<div class="endeasyrecipe" style="display: none;">3.2.1255</div>
</div>
<p> </p>
<p><a href="http://mywebsite.in.cp-25.webhostbox.net/wp-content/uploads/2013/09/Biryani-2.jpg"><img class=" wp-image-411 alignright" alt="Biryani-2" src="http://mywebsite.in.cp-25.webhostbox.net/wp-content/uploads/2013/09/Biryani-2.jpg" width="189" height="142"></a></p>
<p>Recipe Ingredients are lengthy.. But it looks only onscreen.. Once you start preparing them they does not seem long or more.. Basic Ingredients, Easy Recipe and Traditional Hyderabadi Taste.. Dont forget to try it, I am sure you'll love it and make it again and again!!!</p>
<p><a href="http://www.youtube.com/mywebsite" target="_blank">Do Subscribe on YouTube</a></p>
<p><a href="http://www.fb.com/mywebsite" target="_blank">Like us on FB</a></p>
<p> </p>
<p>Video Recipe:</p>
<p><iframe src="//www.youtube.com/embed/zf0_AJfp5AA" height="500" width="835" allowfullscreen="" frameborder="0"></iframe></p>
答案 0 :(得分:2)
答案是以下变化:
update wp_posts
set post_content = CONCAT(LEFT(post_content, LOCATE('div style=', post_content)-1),
SUBSTRING(post_content, LOCATE('</div>', post_content)+7))
where LOCATE('div style=', post_content) > 0
将“div风格”更改为无效的开头。
答案 1 :(得分:1)
您的查询已关闭,但您需要使用LOCATE和INSTR来查找嵌入字符串的结尾:
select
ID,
post_title,
substr(post_content,
instr(post_content,'<div style="position:absolute'),
LOCATE('</div>',post_content,instr(post_content,'<div style="position:absolute')+30)-instr(post_content,'<div style="position:absolute')
+6) as temp
from wp_posts
where post_content LIKE '%<div style="position:absolute%'
LIMIT 10
请参阅此处的示例:http://sqlfiddle.com/#!2/d0cf2f/13
答案 2 :(得分:0)
您可以使用以下查询进行此替换:
UPDATE Customer SET address = REPLACE(address, substring_index(substring_index(address, 'prefixString', -1), 'postfixString', 1), '') WHERE address IS NOT NULL;
例如:
地址:黑助推鹿街
用空字符串替换 booster。
UPDATE Customer SET address = REPLACE(address, substring_index(substring_index(address, 'Black', -1), 'deer', 1), ' ') WHERE address IS NOT NULL;