Jump to content


Photo

templates, slashes, and eval


  • Please log in to reply
1 reply to this topic

#1 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 13 June 2006 - 09:07 PM

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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 12:35 AM

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.

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

~ D Kuang




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users