I have this piece of code:
echo preg_replace('/\!(.*)\!/', file_get_contents('${1}'), $str);
What it is meant to do is replacing all !...! with the contents of the file specified between the exclamation marks. However, it is not working because ${1} is not getting replaced:
Warning: file_get_contents(${1}) [function.file-get-contents]: failed to open stream: No such file or directory
If I code:
echo preg_replace('/\!(.*)\!/', '${1}', $te);
everything is fine (i.e. the text between !...! is replaced by the text itself).
How can I make the ${1} in file_get_contents also be replaced?
There you go. Use preg_replace_callback for this kind of replacements, where you need to call a custom function on the matches that would give the replacement string.