I have two types of bbcode:
[Attachment]1234[/Attachment]
[attach=full]1234[/attach]
$message = 'this is message with attach [attach=full]1234[/attach]
I want to remove everything in the string and use:
(preg_match_all('/\[ATTACH((.*?)\](.+?)\[\/ATTACH\]/i', $message, $out, PREG_SET_ORDER))
if (preg_match_all('/\[ATTACH((.*?)\](.+?)\[\/ATTACH\]/i', $message, $out, PREG_SET_ORDER)) { for ($i=0;$i<count($out);$i++) { $replace_src[] = $out[$i][0]; $replace_str[] = $out[$i][1]; $newMessage = str_ireplace($replace_src, $replace_str, $message); } }
This code deletes [attach][/attach], but does not delete [attach=full][/attach]
=full
exists in the message.
Use
preg_replace()
instead ofpreg_match_all()
.Use the optional group to match the optional
=xxx
afterattach
.