4

When I write

<?=?>

in my PC it's not working,but it's work in another PC !!! why ??? :( for example :

<?php
$courses = CourseManager::findAll();
?>
<h3>Course List</h3>
<table>
    <tr><th>Name</th></tr>
 <?php   foreach ($courses as $c){
?>
    <tr>
        <td><?=$c->getName()?></td></tr>
  <?php } ?>

</table>

or this, it's too simple no ? :)

<?= expression ?>

This is a shortcut for

<? echo expression ?>

or

<?php
$i ="test";
?>

<h1><?=$i?></h1>

Thanks for your advice :)

hakre
  • 193,403
  • 52
  • 435
  • 836
Freeman
  • 9,464
  • 7
  • 35
  • 58

5 Answers5

6

You don't have the short tags enabled.

To enable them look for short_open_tags in php.ini. Change it to "On" and restart Apache.

codaddict
  • 445,704
  • 82
  • 492
  • 529
6

PHP's short_open_tag options isn't the same on different servers. If possible avoid to use these type of opening tags.

If you want to be sure short open tags are available, set it yourself with ini_set.

fabrik
  • 14,094
  • 8
  • 55
  • 71
0

Check short_open_tag in php.ini

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
Piotr Müller
  • 5,323
  • 5
  • 55
  • 82
0

Because these shortcuts can be turned off in the php.ini. The option is called short_open_tags.

0

See this: http://www.php.net/manual/en/language.basic-syntax.phpmode.php

Mchl
  • 61,444
  • 9
  • 118
  • 120