I am trying to replace content of some tags in included files with content from other files:
$view = preg_replace('/{include ([[:alnum:]\.-]+)}/', ((file_exists('template/$1.html')) ? 'OK $1' : 'KO $1'), file_get_contents('myTemplateFile.tpl'));
All the {include file.ext}
references I got in myTemplateFile.tpl
are replaced with KO file.ext
instead of OK file.ext
.
However, if I hardcode file_exists('template/file.ext')
, then the right string is displayed.
It appears to me the back-reference is not correctly resolved inside the file_exists
call.
What am I doing wrong?