PHP inside Image Tag [duplicate] - php

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'/>

Related

Echoing variable in php [duplicate]

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>

How to Use a Variable which is a URL and pass it to a href tag so it opens as a Hyperlink in HTML code [duplicate]

This question already has answers here:
Insert php variable in a href
(4 answers)
Closed 7 years ago.
var= www.google.com
Now I want to pass this variable to an a href tag, how shall I do it?
I tried doing below but it didn't work. I need to pass it as variable since every time the url is going to be different.
NoAbTerm
Appreciate your any help.
If you want the variable as php, you could do this:
$whatevervariable = "http://www.google.com";
/* then, you can echo it out */
echo"
<a href='".$whatevervariable."'>google</a>
";

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

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

how to extract data from mysql that contains special characters? [duplicate]

This question already has answers here:
php echoing angle brackets
(4 answers)
Closed 9 years ago.
Example data in my database:
blabla<blabla
I use phpmyadmin and can see that the data has been input successfully.
However when I try to display the data what I get is:
blabla NOT blabla<blabla
In other words, everything after the < symbol does not display.
<?
while ($mouselist_row = mysql_fetch_array($mouselist)) {
$mouselist_commonstrain = mysql_real_escape_string($mouselist_row['Common_Strain']);
echo "$mouselist_commonstrain.";
}
?>
I tried using mysql_real_escape_string.
Is there something in particular needed to display the <?
thanks
You want something like:
echo htmlspecialchars($mouselist_commonstrain);
(It needs to be HTML escaped.)
try this
$mouselist_commonstrain = stripslashes(htmlspecialchars($mouselist_row['Common_Strain']));
Your problem isn't escaping SQL but HTML. As answered in this question you can use htmlspecialchars function.

Categories