Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/11918-templates-slashes-and-eval/
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.