Reputation: 29
I'm looking for something much like the Using PHP variables inside HTML tags? question, but a little different.
In my case, I'd like to use code ore like this:
$somevar = 'a test';
include("file.html");
and file.html would contain
<b>hello, this is {$somevar}</b>
The problem is that it just prints hello, this is {$somevar}
.
How can I make the HTML read the vars in the included file?
Upvotes: 2
Views: 131
Reputation: 912
<?php
include "stuff.php";
$somevar = "test";
?>
<html>
<body><p><?php echo($somevar); ?></p></body>
</html>
Upvotes: 0
Reputation: 5239
You need to include the variable defining program, in the other program wanting to access it. Example:
Say test.html has $somevar.
in file.html you do,
<?php
include('test.html');
echo "<b>hello, this is $somevar</b>";
?>
Upvotes: 0
Reputation: 16828
echo "<b>hello, this is {$somevar}</b>";
or
<b>hello, this is <?=$somevar?></b>
or
<b>hello, this is <?php echo $somevar; ?></b>
or
<b>hello, this is <?php print $somevar; ?></b>
Upvotes: 1