This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What does '<?=' mean in PHP?
I'm reading someone else's code and I don't think I've come across this before.
if((< ? =date("Y");?>-parseInt($('#year').find('option:selected').val()))<18)
Any thoughts?
Thanks
<?= is the short open and echo tag. Here is the PHP documentation for it.
<?= is short-hand for <?php echo, but only works if php.ini is setup properly.
Same as <?php echo ...
It is not always enabled in some environments.
That evaluates to:
if((<?php echo date("Y"); ?>-parseInt($('#year').find('option:selected').val()))<18)
But I think its recommended for you to use <?php echo '';?> instead of <?= ?> for compatibility reasons.
Related
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What does '<?=' mean in PHP?
(8 answers)
Closed 7 years ago.
In some PHP scripts (actually it's the first time I've met this, in yii2 code), the <?= ?> tags are used. I'm not sure how these work, because their behavior is quite mysterious:
<?=
$a = 10;
echo $a . "\n";
This outputs, surprisingly, 1010, and not 10. I'm surprised that such special behavior finds no mention in the PHP manual also (or maybe I didn't look hard enough).
<?= this is the short tag in php.
Its equivalent to <?php echo
Your code is executed as
<?php
echo $a = 10;
echo $a . "\n";
<?= is replaced with <?php echo
So you are getting 10 twice in output.
<?php echo 'whatever'; ?>
<? echo 'whatever'; ?>
and
<?='whatever';?>
are the same thing.
Just make sure you have short_open_tag = On in php.ini.
It basically saves you from typing as much.
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 7 years ago.
For printing any PHP variable the following syntax is used sometimes
<?= $x ?>
Can anyone please explain when should I use this instead of
<?php echo $x; ?>
and what the name of that operator <?= ?
Any help is appreciated.
it's fast echo.
You can use it with html.
<div class="<?=$your_class"></div>
It's a "short tag"; this one is an abbreviation for "<?php echo". You need to be careful when using it or any other short tags as not all servers are configured to render them correctly.
A bit more info can be found here: http://php.net/manual/en/language.basic-syntax.phptags.php
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
PHP echo vs PHP short echo tags
(6 answers)
Closed 9 years ago.
What is the use of the following symbols in php?
<?= code($data); ?>
Though I don't know the actual use of the above symbol, I found out that I can use
<?= my_function($data1,$data2); ?>
instead of using
<?php echo my_function($data1,$data2); ?>
Can anyone explain what exactly is happening here and what is the use of it?
It's a quick way of echoing text, as that's one of the most common uses of PHP.
As of PHP 5.4, <?= ?> is essentially the short-hand way of writing <?php ?>.
This question already has answers here:
What does '<?=' mean in PHP?
(8 answers)
Closed 9 years ago.
I recently discovered some code that output a variable in php like this:
<?=$var;?>
I have never seen this before. Is it the same as
<?php echo $var;?>
?
<?=$var;?>
is the same as
<?php echo $var;?>
But it will only work if you have:
short_open_tag=On
in your php.ini
As of php 5.4 short_open_tag isn't required. The shorthand version is always available. http://php.net/manual/en/ini.core.php#ini.short-open-tag
#jszobody: Thanks for your comment!
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Are PHP short tags acceptable to use?
So I noticed that you can write PHP programs either like
<?php
// do something
?>
or
<?
// do something
?>
What's the difference and what's the best practice?
I always use
<?php
because in some hosts the short tags are not allowed. This avoids some headaches.
There's no difference at all. Except
<?= $var ?>
that acts like an "echo"
You should use <?php whenever possible, with short_open_tag=off (see php.ini) <? just won't work and code will be treated as html.