Q:

php array and html

OK i have 2 files one is index.php and the other is file.html now i want to display my array content through that html file like calling it and then displaying here is the code
index.php:

$var1 = 'text';

array('var' => $var1);

include ('file.html');

file.html:

<p>html {var} html</p>

now its not displaying text i have seen people use {} and call the key and display its value how do i do that? all i want is display my values through the html file not with echo or using php open close codes in between the html codes.

A:

If you want to replace tags {name} to value with $a = array('name' => 'value'); you can use str_replace();
$filehtml = file_get_contents('file.html');
$array = array('var' => 'value');

foreach($array as $tag => $value)
{
  $filehtml = str_replace('{'.$tag.'}', $value, $filehtml);
}

echo $filehtml;

Or you use Smarty (or others).

