Jump to content

Archived

This topic is now archived and is closed to further replies.

robos99

templates, slashes, and eval

Recommended Posts

I have a template with html and some php variables inside it. This is stored in a database. What I'm trying to do is make it work so that the variables will show up when the template is displayed.

I've tried using eval, but I keep getting parse errors because of the slashes in the template. magic_quotes_runtime is off and magic_quotes_gpc is on. When I don't add any additional escaping to the slashes I get the parse errors I would expect. But when I do addslashes I get
"Warning: Unexpected character in input: '\' (ASCII=92)"

And then I get parse errors from the variables within the html.
"Parse error: parse error, unexpected $ "

I've tried everything and I'm all out of ideas.

Share this post


Link to post
Share on other sites
Don't do this (have a template with variables and then use eval).
It's more headache than you can imagine. Instead, use placeholders, and then str_replace.

[code]$html = '<title>{_TITLE_}</title>';
$output = str_replace('{_TITLE_}', $title, $html);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.