I have a complicated problem:
I have a very long text and I need to call some php functions inside my text.
The function name is myfunction();
I`we included in my text the function in the following way:
” text text text myfunction[1,2,3,4,5]; more text text … “
And I want to replace each myfunction[…] with the result of the function myfunction with the variables from the [] brackets.
my code is:
<?php echo preg_replace('/myfunction[[0-9,]+]/i',myfunction($1),$post['content']); ?>
,but it`s not working.
The parameter should be an array, because it can contain any number of values.
If I were you, I would avoid using the
emodifier topreg_replacebecause it can lead you open to execution of arbitrary code. Usepreg_replace_callbackinstead. It’s slightly more verbose, but much more effective:This uses an anonymous function. This functionality won’t be available to you if you use a version of PHP before 5.3. You’ll have to create a named function and use that instead, as per the instructions on the manual page.