Core
Core

Reputation: 335

Echo html files with variables

I need to be able to include an html file that has variables in it, and then have those variables replaced with their values, and then finally echoed out. This is my PHP:

error_reporting(E_ALL);
$CONTENT="CONTENT";
define(PAGE_TITLE, "title");
include("index.html");

and my HTML file:

<html>
<title>{PAGE_TITLE}</title>
<p>{$CONTENT}</p>
<p>{$ARR}</p>
</html>

Upvotes: 1

Views: 390

Answers (2)

BRBT
BRBT

Reputation: 1487

You need to include php tags in your html elements, and if you want to output the value of the variable you need to echo it.

Try this:

<html>
<title><?php echo PAGE_TITLE; ?></title>
<p><?php echo $CONTENT; ?></p>
<p><?php echo $ARR; ?></p>
</html>

Upvotes: 0

LostPhysx
LostPhysx

Reputation: 3641

You can use php shorttags:

<html>
<title><?=PAGE_TITLE?></title>
<p><?=$CONTENT?></p>
<p><?=$ARR?></p>
</html>

Upvotes: 1

Related Questions