Echoing variable in php [duplicate] - php

This question already has answers here:
How to enable PHP short tags?
(21 answers)
Closed 6 years ago.
Essentially I am trying to have a heading using what is below. Not sure what is going on but nothing happens. Even when I do something as simple as echo "hello" there instead of the 2 variables.
<h1><?echo "$info[0] ($info[1])";?></h1>

You can use <?= ?> shorthand for echoing variables and the code should look like,
<h1><?= "$info[0] ($info[1])"; ?></h1>

Try using this way. You are missing <?php.
<h1> <?php echo $info[0] .'('. $info[1] .')'; ?> </h1>

Related

I am not sure php inside [duplicate]

This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 6 years ago.
Ya here is my code.
<?php print "<?php echo $this->lang('learn_cn')?>" ?>
It comes with blank nothing show.
<?php echo $this->lang('learn_cn')?>
What is the correct way to make this work. TY
You're already in the process of printing out HTML, so just escape that part like you did in the href:
<?php print "" . $this->lang('learn_cn') . "" ?>

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

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

PHP inside Image Tag [duplicate]

This question already has answers here:
php - insert a variable in an echo string
(10 answers)
Closed 8 years ago.
I would like to insert PHP variables inside image tag. Can you please help me in writing the code with escape characters
<img src='"Images/"<?$j_$i?>.jpg'/>
You should only use <?php
<img src='Images/<?php echo $j.'_'.$i; ?>.jpg'/>
It's not beautiful,but it's always supported by server
You need to actually output something.
Use <?= instead of <?.
Change this:
<img src='"Images/"<?$j_$i?>.jpg'/>
To:
<img src='Images/.<?php echo $j .'_'. $i;?>.jpg'/>

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

Better to write <?php or <? [duplicate]

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.

Categories