正则表达式
程序员文章站
2022-04-14 17:49:48
...
[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]
如何把[img] 与[/img]之间的内容替换成空?
回复讨论(解决方案)
$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?[img][/img]
$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?[img][/img]$s = '[a]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/a]';echo preg_replace('/(?[a][/a]
a标签或其它标签包含的内容也被替换了,怎么把它写死,仅针对[img][/img]
echo preg_replace('/(?
$str = '[img]XXXXX[/img]';$regx = '/\[img\](.*)\[\/img\]/';$rep_result = preg_replace_callback( $regx, function($match){ return str_replace($match[1],'',$match[0]); }, $str);