【问题标题】:What is the meaning of $1 and $2 in the Blade::extend functionBlade::extend函数中$1和$2是什么意思
【发布时间】:2015-03-18 18:59:44
【问题描述】:

我在Laravel Docs看到了这个例子:

Blade::extend(function($view, $compiler)
{
    $pattern = $compiler->createMatcher('datetime');
    return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/Y H:i\'); ?>', $view);
});

不过我好像没看懂,有的时候网上的例子包括$3。

我没有通过 Google 搜索找到正确的答案,感谢您的帮助。

【问题讨论】:

    标签: php laravel laravel-4 blade


    【解决方案1】:

    这是一个字符串替换!它将变量(例如$1)替换为模式的匹配组!

    作为示例(伪代码):

    $pattern = "/(.*?)([a-z])/";
    //Here is $1 ^ This group and $2 would be the second group
    

    也作为附加帮助:

    PHP regex Cheat Sheet

    Online Regex tester

    【讨论】:

    • 当我看到$compiler-&gt;createMatcher()函数的代码时,我明白了更多.
    猜你喜欢
    • 2016-08-18
    • 2020-02-15
    • 2010-10-23
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    相关资源
    最近更新 更多