Home  >  Article  >  Backend Development  >  正则表达式

正则表达式

WBOY
WBOYOriginal
2016-06-20 12:51:141140browse

[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]

如何把[img] 与[/img]之间的内容替换成空?


回复讨论(解决方案)

$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?<=])[^[]+/', '', $s);
[img][/img]

$s = '[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]';echo preg_replace('/(?<=])[^[]+/', '', $s);
[img][/img]


$s = '[a]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/a]';echo preg_replace('/(?<=])[^[]+/', '', $s);
[a][/a]
a标签或其它标签包含的内容也被替换了,怎么把它写死,仅针对[img][/img]

echo preg_replace('/(?<=\[img\])[^[]+/', '', $s);

$str = '[img]XXXXX[/img]';$regx = '/\[img\](.*)\[\/img\]/';$rep_result = preg_replace_callback(	$regx, 	function($match){		return str_replace($match[1],'',$match[0]);	},	$str);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:安装php加速缓存Next article:PHP获取$_GET[gsid]值问题