duandu9260 2013-11-12 22:06
浏览 21
已采纳

一个PHP解释与the_content过滤器

first of all i have this code

function Huemix_content_filter_qm($content){
    $item = '\?';
    $before='<span class="kindared">';
    $after='</span>';
    $content = preg_replace("|($item)|","$before$1$after",$content);
    $content = preg_replace("|(<[^>]+?)($before($item)$after)([^<]+?>)|","$1$3$4",$content);

    return $content;
}

add_filter('the_content', 'Huemix_content_filter_qm');

i can under stand the whole code but this three vars $1$3$4 can any one tell me what they are, cuz as i did i never define them !

  • 写回答

1条回答 默认 最新

  • dongpao2871 2013-11-12 22:07
    关注

    From the manual:

    replacement may contain references of the form or (since PHP 4.0.4) $n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n'th parenthesized pattern. n can be from 0 to 99, and \0 or $0 refers to the text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern. To use backslash in replacement, it must be doubled ("\\" PHP string).

    Basically each one represents a match in parenthesis in the regex. The number represents which match it is. $1 represents what is matched with (<[^>]+?), $3 matches ($item), and $4 matches ([^<]+?>).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站