1

i am trying to search my database for the string <strong>some text here</strong> and replace it with s<strong>ome text here</strong>

basically find the first <strong> then find the first character and place it in front of the <strong>

maybe use something like here

is this complex enough? :)

thanks

Patrioticcow
  • 26,422
  • 75
  • 217
  • 337

2 Answers2

2

There is no regexp replace support in MySQL so you'll have to do the replacing in PHP and then do the update (or implement some sort of UDF for MySQL, see How to do a regular expression replace in MySQL?).

In PHP you'll use something like (after fetching all rows into a $rowset):

foreach($rowset as $row) {
  $replacement=preg_replace('/<strong>(.)/','\1<strong>',$row->fieldname,1);
  myDBCall('update mytable set myfield="'.$replacement.'" where someid='.$row->someid);
}
Community
  • 1
  • 1
Bing
  • 746
  • 5
  • 7
-1

You would use something like:

update `table` set `fieldname` = replace(`fieldname`,'string_to_find','string_to_replace_with')
Latox
  • 4,655
  • 15
  • 48
  • 74