Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables / scope / includes 2

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Hi,

I seem unable to access a variables I created from within my include file?

index.php
Code:
<?php

$title_tag = 'This is a title ';
 
include('includes/header.php');

?>

header.php
Code:
<title><?php $title_tag ?></title>

What am I doing wrong?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Download
 
Just to clarify, you were simply not outputting the value at all. You need to use the equal sign with the PHP opening tags or an echo or print.

Placing a variable inside PHP tags does nothing to it.

Code:
<?php $myVar ?>

Code:
<?php echo $myvar; ?>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
you may have seen this notation in older examples (and will start seeing it again now that php 5.4.0 has enabled this as default functionality, irrespective of ini settings)
Code:
<?= $value ?>
this is synonymous with
Code:
<?php echo $value; ?>

until recently this was not regarded as good practice because it required that php had short_tags turned on. and short_tags were discouraged because of xml compatibility. however from 5.4.0 using the <?= short cut is no longer discouraged.
 
they are indeed on by default. although I remember that they weren't for at least some versions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top