Use of Variables in HTML/PHP?

John

New member
Hi! In some website code I have at the top of the HTML file a PHP include of another html file as such:
<?php
include("template1.html");
?>

I am trying to do the following:
<?php
$PageTitle = "My Page title";
include("template1.html");
?>

Then inside template1.html use the defined PHP variable in this way:
echo "<title> $PageTitle </title>;

Should this work?

Regards,
JohnD
Of the answers provided by Jacer12 below (thanks!) #2 worked and #1 did not. Not sure what the issue is with #1. Also, It seems I cannot rate the answer or select best answer since I am level1.
 
No. You can't have variables inside the quotes. There are few options you can use.

1.)
<title> <? echo $PageTitle; ?> </title>

2.)
echo "<title>" . $PageTitle . "</title>";


You can contact me if you have any more questions.
 
Back
Top