Jump to content

Replace part of string woes


parallax

Recommended Posts

Hi, I have a few questions related to the MySQL (my version is 4.1.20) function Replace.

 

I have a couple of thousand entries in a table, 'descriptions', that are all built on the same html template. But they all have a few html errors which needs to be changed, in other words a small part of a string needs to be replaced in all these records (the string is simple and unique so that is not a problem). As such I figure the best way to go about this is the Replace function in SQL, not any PHP functions such as str_replace, would that be correct?

 

I am not sure wether the standard Replace function such as:

 

UPDATE yourtable SET yourfield = REPLACE(yourfield,"some_string","some_new_string")

WHERE yourconditions.

 

would do what I am after? Any advice?

Link to comment
https://forums.phpfreaks.com/topic/96381-replace-part-of-string-woes/
Share on other sites

Yeah that was first on my to-do-list, to backup the database. Also going to run it on a copy of the table first to see if everything went well ;D

 

I am wondering about one thing though. Since the part to be replaced contains html with quotes, how does sql render that in the syntax?

 

For instance: REPLACE(description,"%size="2"%","%size="1"%")

 

Looks kind of odd. Should I maybe use ''? ie. description, 'size="2"', or is it fine as is?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.