karto
karto

Reputation: 3658

php/mysql search and replace a parts of a sentence

Replacing parts of a sentence in mysql table using php.I need help in getting this done rightly. eg. replacing http://www.gettingthingsdone.com/products/electronics with http://www.gettingthingsdone.com/electronics

$sql = "UPDATE ".$table_name."
                        SET ".$val." = '".$SearchAndReplace_replace_with."'
                        WHERE ".$val." LIKE '"."%".$SearchAndReplace_search_term."%"."'";

Upvotes: 0

Views: 380

Answers (1)

Shakti Singh
Shakti Singh

Reputation: 86336

You should consider to use REPLACE of mysql that is designed what are you looking for. before executing the command take the backup of table.

   UPDATE [your_table_name] SET [your_table_field] = REPLACE([your_table_field],
 '[string_to_find]' , '[string_to_be_replaced]')

Upvotes: 3

Related Questions