Passionate Engineer
Passionate Engineer

Reputation: 10422

Change image subdomain string in HTML column MySQL

I'm trying to change "www." to "cdn." for every img element in the MySQL database.

This is HTML column so it's a bit tricky with other elements like a tags in there also but I just want to change img tags

I've tried LIKE '%test%' but not sure how to use UPDATE for this situation

What's the best way to do this?

Below is an example:

 

[nivoslider id="1952"]

 

[one-third first]
<h2><a title="diet" href="http://www.test.com.au/diet">Diet and Nutrition</a></h2>
<a title="diet" href="http://www.test.com.au/diet"><img class="size-full wp-image-965 alignnone" title="diet-and-nutrition-information" alt="diet-and-nutrition-information" src="http://www.test.com.au/wp-content/uploads/2012/10/Optimized-diet-and-nutrition-information.jpg" width="310" height="220" /></a>
A dietitian provides assistance and education for every day meal and exercise plans and provides advice and modified diet plans to treat health and medical conditions. Our dietitian is here to educate you and your family about healthy ways of living to reduce or maintain a healthy weight, cholesterol levels and detoxify our bodies to live a longer, healthier, more active lifestyle. Combined with nutrition, our dietitian and nutritionist can assist with food intolerances, digestive system and eating disorders and sports nutrition. <a title="Diet and Nutrition" href="http://www.test.com.au/diet-and-nutrition/"><strong>Read more.</strong></a>[end-column]

[one-third]
<h2><a title="skincare" href="http://www.test.com.au/skincare">Skincare</a></h2>
<a href="http://www.test.com.au/skincare/"><img class="alignnone size-full wp-image-1793" title="skincare-information" alt="skincare" src="http://www.test.com.au/wp-content/uploads/2012/10/Optimized-skincare-information3.jpg" width="310" height="220" />
</a>Human skin is our body’s largest organ. It is a complex series of layers of cells and its function is to provide a natural barrier to many things. As with any other organ in the body, you should take care of your skin and keep it healthy. There are many basic skincare steps you can take throughout your life to keep your skin looking fresh and feeling good from cosmetics to natural procedures and techniques. Understanding, caring and treatment of skin conditions and diseases is an important part of skincare and your overall health. <strong><a title="Skincare" href="http://www.test.com.au/skincare/">Read more.</a></strong>[end-column]

[one-third last]
<h2><a title="speech-pathology" href="http://www.test.com.au/speech-pathology">Speech Pathology</a></h2>
<a title="speech-pathology" href="http://www.test.com.au/speech-pathology"><img class="size-full wp-image-967 alignnone" title="speech-pathology" alt="speech-pathology" src="http://www.test.com.au/wp-content/uploads/2012/10/Optimized-speech-pathology-information.jpg" width="310" height="220" /></a>
Speech and language pathology is concerned with issues surrounding human speech and language communication disorders. Assistance with producing words can be helpful to both children and adults who lack clear speaking skills. Conditions treated at ENT Wellbeing include cognitive-linguistic, oral motor, language, swallowing, stuttering, voice, and speech disorders. Our ENT Wellbeing speech pathologist will perform a comprehensive diagnosis so that an effective treatment plan can be customized for the patient. <strong><a title="Speech Pathology" href="http://www.test.com.au/speech-pathology/">Read more.</a></strong> [end-column]

[schemaLocalBusiness]

I tried below and it's not working:

UPDATE posts SET post_content = replace(post_content, 'src=\"http\:\/\/www\"', 'src=\"http\:\/\/cdn\"');

Upvotes: 2

Views: 106

Answers (1)

juergen d
juergen d

Reputation: 204924

update table set column = replace(column, 'www.', 'cdn.')

Upvotes: 1

Related Questions