domino
domino

Reputation: 7345

preg_replace removing a text and tags

preg_replace('|[[\/\!]*?[^\[\]]*?]|si', '', $text);

This removes all the bb tags from the text. I am looking to remove the persons's signature as well. This has to be done before the tag replacement and I'd like to do it with one regex.

This should be removed completely:

[b][color=red]This is my signature[/color][/b]

Been playing around with it for a while and got nowhere.

Upvotes: 0

Views: 271

Answers (2)

hakre
hakre

Reputation: 198209

Just write what you look for as a pattern:

$pattern = '(\[b]\[color=red](?:\w|\s)*\[/color]\[/b])';

Escape those characters which have a special meaning (e.g. the opening square bracket [).

That should do it.

Upvotes: 2

Adam Wolski
Adam Wolski

Reputation: 5676

for example something like this should work:

/((\s?\w)+|[[\/\!]*?[^\[\]]*?])/

Upvotes: 0

Related Questions