Forum Moderators: coopster
in my template system i inject the $content_variables into an htm template which i eval() so the $variables in it can be parsed.
however, when i have a $variable in the middle of a non-broken line, it is not parsed, e.g.:
href="/style/<?php echo $style01;?>.css works, but
/graphics/top_<?php echo $graphics_color;?>_06.gif does not
i am sure this has something to do with symbols / characters which specify a break of sorts, but i can't work it out?
any help is much appreciated
thanks!
the <?php echo is not there, because it is an htm file which i am using (my mistake). my code for the eval is:
foreach( file("templates/$the_template.htm") as $line ) {
$main_template .= $line;
}
eval("\$str = \"" . str_replace("\"", "\\\"", $main_template) . "\";");
which escapes all my " in the html file.
now when i have a variable in the middle of an unbroken line:
top_$graphics_color_02.jpg
only top_02.jpg is displayed
but when i add a full stop:
top_.$graphics_color._02.jpg
top_.standard._02.gif is displayed.
i.e the $variable is being substituted correctly, but of course the full stops are still there!
the same thing happens when i escape \_ the underscore:
top\_$graphics_color\_02.jpg
becomes top\_standard\_02.jpg
thanks :)
<added>
after careful studying of the eval() manual page, i have solved it. i needed to escape the following undersore as you suggested and then stripslashes($main_template).top_$graphics_color\_02.jpg
works perfectly!
many thanks for putting me in the right direction!