Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site was well structured and I found what I was looking for in about 2 minutes. I am looking forward to participating with you in the future..."

Geography

Where in the world do Tek-Tips members come from?

variables / scope / includesHelpful Member!(2) 

1DMF (Programmer)
14 May 12 10:26
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!"

[link http://dance-music.org]Free Electronic Dance Music Download

1DMF (Programmer)
14 May 12 10:37
it's OK, found a way of doing it

CODE

$SYSN['title'] = 'XYZ' and then <?=$SYSN['title']?>

"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!"

[link http://dance-music.org]Free Electronic Dance Music Download

Helpful Member!  vacunita (Programmer)
14 May 12 10:44
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

1DMF (Programmer)
14 May 12 11:10
OIC - thanks Phil.

I don't do PHP normally, so am a total noobie!

"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!"

[link http://dance-music.org]Free Electronic Dance Music Download

Helpful Member!  jpadie (TechnicalUser)
14 May 12 11:40
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.
1DMF (Programmer)
14 May 12 11:52
cool, thanks jpadie.

I guess short_tags are on by default in the windows environment I am using, as it worked first time without issue.

"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!"

[link http://dance-music.org]Free Electronic Dance Music Download

jpadie (TechnicalUser)
14 May 12 12:01
they are indeed on by default. although I remember that they weren't for at least some versions.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close