20,359
社区成员
发帖
与我相关
我的任务
分享
<?php
$content='<php>asdfsadf</php><php>asdfsadf</php><php>asdfsadf</php><php>asdfsadf</php><php>asdfsadf</php><php>asdfsadf</php> testtest';
$a=123;
$content= preg_replace_callback('/<php(\s*?)>(.*?)<\/php(\s*?)>/is', function($match) use($a){return 123;}, $content);
echo $content;
$content = preg_replace_callback('/[a-z]/', function ( $matches ) {
return strtoupper($matches[0]);
}, 'abdfrew');
echo $content;
与之等价的分立代码为
$content = 'abdfrew';
preg_match_all('/[a-z]/', $content, $matches );
foreach($matches[0] as $v) $r[$v] = strtoupper($v);
$content = strtr($content, $r);
echo $content;
先分别运行一下,看有无问题
if (! $closeTag)
{
$patterns = '/' . $begin . $parseTag . $n1 . '\/(\s*?)' . $end . '/is';
$content = preg_replace_callback($patterns, function ( $matches ) use( $tLib , $tag , $that )
{
return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]);
}, $content);
} else
{
$patterns = '/' . $begin . $parseTag . $n1 . $end . '(.*?)' . $begin . '\/' . $parseTag . '(\s*?)' . $end . '/is';
for ($i = 0; $i < $level; $i ++)
{
$content = preg_replace_callback($patterns, function ( $matches ) use( $tLib , $tag , $that )
{
return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]);
}, $content);
}
}