template and echo

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Consider this:

  $mm = file_get_contents("123.tpl");
  $var1 = 'abc';
  echo ($mm);

'123.tpl' is actually a html file with string '$var1' somewhere in the

I want to display the HTML file but I want to replace '$var1' with
another value.

Would there be any problem or side effect ?


Re: template and echo

On Thu, 22 Jan 2009 01:56:26 -0800 (PST), sb5309@yahoo.com wrote:
Quoted text here. Click to load it

No, file_get_contents() simply reads the bytes and stores the data in
a string when successful.  PHP does not execute anything in files
read by file_get_contents().

OTOH, there might be side effects when using the require, include,
require_once, or include_once constructs.

$email = str_replace('sig.invalid', 'gmail.com', $from);

Re: template and echo

sb5309@yahoo.com escribi:
Quoted text here. Click to load it

echo str_replace('$var1', 'abc', $mm);

Quoted text here. Click to load it

This will fail if your template has place holders like $var1 and $var12.
You might try a different syntax like , %var1%, [[[var1]]]...

-- http://alvaro.es - lvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programacin web: http://bits.demogracia.com
-- Mi web de humor al bao Mara: http://www.demogracia.com

Site Timeline