0

I have a php script which contains few variables e.ct "welcome.php"

<?php
  $hello = '<p class="fontBlack15">we will collect your rent to co-inside with your student loan payments. </p>';
?>

In another php script "hello.php" i have:

<?php include 'welcome.php';?>

<div id="header"><? echo $hello; ?></div>

This doenst work... and i dont really know much why?

Thank you

4
  • What is happening when you run your script? Commented Jul 17, 2014 at 11:29
  • you are working on localhost or at server?? Commented Jul 17, 2014 at 11:30
  • Are you get error? put that. Commented Jul 17, 2014 at 11:30
  • 1
    <?php please not <? Commented Jul 17, 2014 at 11:31

4 Answers 4

2

This is because XAMPP doesn't allow using the short version of PHP syntax.

<div id="header"><?php echo $hello; ?></div>

You must use <?php instead of <?

Sign up to request clarification or add additional context in comments.

Comments

2

Probably you should change

<div id="header"><? echo $hello; ?></div>

into

<div id="header"><?php echo $hello; ?></div>

or change short_open_tag to 1

EDIT

Or if you use PHP 5.4+ you can also simple use:

<div id="header"><?= $hello; ?></div>

to display variable's value regardless of short_open_tag settings

Comments

0

Please check whether your short tags are working. else go to php.ini file and uncomment short_open_tag

Comments

0

Though you did not specify whether your files are in same directory or not? If the answer by Ozan Kurt and Marcin Nabiałek didn't workout for you, then may be your files are in a different directories and for that you have to give directory path in your include e.g.

<?php include '../your_file_path/welcome.php'; ?> 

then

<div id="header"><?php echo $hello; ?></div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.