PHP正则处理非匹配项,该如何处理

WBOY
Release: 2016-06-13 13:46:38
Original
973 people have browsed it

PHP正则处理非匹配项
比如要将...?>标签以外的代码。例如给加上花括号。

要求是把下面的代码:
aaa...?>bbb...?>ccc
要处理成这样:
{aaa}...?>{bbb}...?>{ccc}

注意...?>中间的内容和...?>以外的内容都是不固定的。
而我们需要处理的是...?>外面的东西。就是aaa,bbb,ccc那些东西。

------解决方案--------------------
$a = array('/(.)(.)/');
$b = array('$1}','?>{$1');
echo $c = preg_replace($a,$b,'{'.$str.'}');

自己测试一下
------解决方案--------------------
$s = "aaa...?>bbb...?>ccc";
echo preg_replace("/(^|\?>)(.+)(

{aaa}...?>{bbb}...?>{ccc}

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