我有两种类型的 bbcode:
[附件]1234[/附件]
[attach=full]1234[/attach]
$message = 'this is message with attach [attach=full]1234[/attach]
我想删除字符串中的所有内容并使用:
(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
此代码删除[attach][/attach],但不删除[attach=full][/attach]
=full 存在于消息中。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
使用
preg_replace(),而不是preg_match_all()。使用可选组来匹配
attach后的可选=xxx。$newMessage = preg_replace('/\[ATTACH(?:=.*?)?\](.+?)\[\/ATTACH\]/i', '$1', $message);