I've had a good search and not found anything relevant to my issue, so please dont down vote without showing me where you have a relevant example...
Trying to build template files as a text document to simplify it for others to modify later, but I can't work out how to get PHP to recognize the variables in it.
What I want to work:
//template.txt
Every time I find $foo,
I get a little $bar,
template text.
note: The line breaks are critical for position.
//handler.php
$foo = 'Beer';
$bar = 'Excited';
$file = file('template.txt');
foreach ($file as $line) {
echo $line;
}
What I want this to return:
Every time I find Beer,
I get a little Excited,
template text.
but it is escaping the variable mark ($), and is returning:
Every time i find $foo,
I get a little $bar,
template text.
I tried to do a str replace with:
if (strpos($line, '\$foo')) {
str_replace('\$foo', $foo, $line);
}
(tried with and without the $ symbol, and many variations on this) at best I can get it to recognise the variable name but it is not replacing.
Has anyone had any experience with this?
Really not finding much info on this online. Any help will be greatly appreciated.