I saw this example in the 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);
});
but I don't seem to understand it, and some time the examples in the web include $3.
I didn't find a proper answer to this through a Google search, I appreciate any help.
It's a string replacement! It replaces the variable (e.g. $1
) with the matching group of the pattern!
As example (Pseudo Code):
$pattern = "/(.*?)([a-z])/";
//Here is $1 ^ This group and $2 would be the second group
Also as additional help:
PHP regex Cheat Sheet
Online Regex tester (<- It visualizes the match of your regex very nice and explains the different parts of your regex)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With