I want to do something like this:
I have this string:
Lorem ipsum {shortcode 42} dolor sit amet.
I want to parse it like this:
preg_replace('/\{shortcode (\d+)\}/i', MyClass::myFunction('$1') , $content);
The MyClass
code looks like this:
class MyClass {
public static function myFunction(string $id) {
// ...
return 'hello world';
}
}
But in the myFunction()
the $id
will always the $1
string, and not the content of the original $1
, what is a number.
How can I pass the preg_replace replacement value in parameter to my function?