What is the name of this " <?= " in php? [duplicate] - php

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

Related

What's the use of <?= ?> tags in PHP? [duplicate]

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.

Why is <? used for and which is the difference with <?php [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 8 years ago.
I am learning php and Ajax, but I see a code where <? is used.
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['id']?>><?=$row['statename']?></option>
Please could you help me to understand why is
You can use
<?=$row['statement'] ?>
as a convenient shorthand to
<?php echo $row['statement'] ?>
this can improve readability.
Read the manual.
It will explain everything about tags.
http://www.php.net/manual/en/language.basic-syntax.phpmode.php

What is the meaning of this symbol in php [duplicate]

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 ?>.

What is <?=$varname?> syntax in PHP code? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 9 years ago.
Previous I bumped into codes like this:
<?php
$var="hello";
?>
<?=$var?>
It simply prints out the content of $var, so... is the syntax equivalent to echo $var?
I'll also appreciate an answer pointing to a related manual page. Since the syntax is not searchable.
Yes, <?=$var?> is the same as <?php echo $var; ?>
From PHP.net manual: echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.
You can read more here.

What does the <?= operator mean in php? [duplicate]

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.

Categories