我在 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 搜索找到正确的答案,感谢任何帮助。
最佳答案
这是一个字符串替换!它将变量(例如 $1
)替换为模式的匹配组!
例如(伪代码):
$pattern = "/(.*?)([a-z])/";
//Here is $1 ^ This group and $2 would be the second group
还有额外的帮助:
Online Regex tester (<- 它很好地可视化了你的正则表达式的匹配,并解释了你的正则表达式的不同部分)
关于php - Blade::extend 函数中 $1 和 $2 的含义是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28047211/