正则表达式

WBOY
Release: 2016-06-20 12:51:14
Original
1153 people have browsed it

[img]XXXXXXg;base64,iVQA/XXXXXXXXXXXXXXX[/img]
Copy after login

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


回复讨论(解决方案)

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

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


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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template