0

I am working on a Client side where they have text like below saved into a MySQL Database, I need to delete it from all entries.

Using PHP or just SQL, can someone help me figure out how this can be done? I have hundreds of records so manually editing each record isn't a viable solution.

The String of text will be like this below, where the text is different for each post record.

Another issue is there could be more then 1 per post record, so I need to simply find the 1st occurance of it and delete it.

<p><strong style="color: rgb(255, 127, 0); font-size: 20px;">
    This is my tile text here, I need to delete these?</strong></p>

Where * could be anything...

<p><strong style="color: rgb(255, 127, 0); font-size: 20px;">*</strong></p>
4
  • So you want to delete what exactly? The part inside the <p> tags or the whole field when this is found? Commented May 17, 2013 at 16:42
  • @migg I am hoping to remove this whole string when it's found in a larger content field...I'm doing this on a WordPress DB. 1 idea I have is using PHP, select the result and iterate each record running a REGEX on it, but I am not sure how the regex should be or if an easier way exists Commented May 17, 2013 at 16:44
  • 1
    "The whole string" is what? Commented May 17, 2013 at 16:47
  • @migg I am trying to delete this whole string <p><strong style="color: rgb(255, 127, 0); font-size: 20px;">*</p> Commented May 17, 2013 at 16:49

1 Answer 1

1
$cleanstring = preg_replace(
    '#<p><strong style="color: rgb\(255, 127, 0\); font-size: 20px;">[^<]*</strong></p>#',
    '',
    $string,
    1
);
Sign up to request clarification or add additional context in comments.

6 Comments

oh nice, I was thinking it would be some complex pattern, thanks
Problem with this pattern is its missing the delimiters and will if added replace anything between the open and the last closing </strong> tag
@migg Are you saying if there is multiple <strong> tags on the page it will capture everything in between the first open and the last closing one?
Now it stops at the first "<" instead.
not anymore after edit, but still missing the delimiters like # or /
|

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.