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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.