递归匹配 和 e修饰符

来源:互联网 发布:java程序员自我评价 编辑:程序博客网 时间:2024/06/05 18:38

$s = '*** $floor_check[$value[$floor[abc]]]***';
在最里层的[abc]加上引号

 function addQuote($str){
     $str = preg_replace("//[([^/[/]]+)/]/","['//1']",$str);
     return $str;
 }
 $s = preg_replace('//$/w+/[([^/[/]]+|(?R))*/]/e',"' /''.addQuote('//0').'/' '",$s);


结果 string(46) "*** '$floor_check[$value[$floor['abc']]]' ***"

搜了很久 这篇日志对我很有用 http://www.uini.net/2010/05/the-recursive-regular-php.html

原创粉丝点击