index.php <?php $mytitle = "Мой заголовок"; $mybody = "Моя страница"; $block0 = file_get_contents('top.htm') echo $block0; ?> top.html <html><head><title> $mytitle </title></head> <body> $mybody </body></html> 

I apologize for the trivial, why not work? What is more correct to use in this case together file_get_contest?

  • what would just include not do? - zb '
  • if not difficult a piece of code - ferrari
  • I’m just a little extrasense that doesn’t work specifically, the file isn’t connected, or the expected result is still there, i.e. are variables displayed as $mytitle and $mybody ? - Palmervan
  • the file is connected, variables are not replaced. - ferrari
  • See the answer! - Palmervan

2 answers 2

index.php

 $title = 'My Title'; $body = 'Body Content'; $top = file_get_contents('top.html'); $top = str_replace ( array ( '$title', '$body', ), array ( $title, $body ), $top ); echo $top; 

top.html

 <html> <head> <title> $title </title> </head> <body> $body </body> </html> 
  • Dear gurus thanks. - ferrari
 $mytitle = "Мой заголовок"; $mybody = "Моя страница"; ob_start(); include 'top.html'; $block0 = ob_get_contents(); ob_end_flush(); 
  • Thanks a good option, isn’t the server going to be very stressful if there are several such Ob_start? - ferrari
  • No, it will not. - Deonis