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

2

2 Answers 2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

-1

You would use something like:

update `table` set `fieldname` = replace(`fieldname`,'string_to_find','string_to_replace_with')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.