This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 5 months ago.
I would like to ask how to display an img src like this:
<html>
<?php
$extradata = (Data for this come from database that I decode)
$profilepicturefinalpath = "/folder/folder/".$extradata;
echo '<img src="<?php echo $profilepicturefinalpath ?>"/>';
?>
</html>
What should I do, Is this possible?
Please help, I am just a newbie
Please try below code. Normal echo with double quotes or heredoc
<html>
<body>
<?php
$extradata = (Data for this come from database that I decode)
$profilepicturefinalpath = "/folder/folder/".$extradata;
echo <<<EOQ
<img src="{$profilepicturefinalpath}" />
EOQ;
echo '<BR>';
echo "<img src='{$profilepicturefinalpath}' />"
echo '<BR>';
?>
</body>
</html>
Related
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 2 years ago.
<?php
$request_uri = $_SERVER['REQUEST_URI'] ;
$path=explode("?",$request_uri);
$pname=basename($path[0]);
if ($pname == "blood-facts-for-kids.html") { $p1 = 'Human Body Facts'; $p1u = 'https://www.factsjustforkids.com/human-body-facts.html'; $p2 = 'Blood Facts'; $p2u = 'https://www.factsjustforkids.com/human-body-facts/blood-facts-for-kids.html'; }
echo '<script type="application/ld+json">{"#context":"https://schema.org/","#type":"BreadcrumbList","itemListElement":[{"#type":"ListItem","position":1,"name":"{$p1}","item":"{$p1u}"},{"#type":"ListItem","position":2,"name":"{$p2}","item":"{$p2u}"}]}</script>';
?>
I'm having issues getting the variables to appear in my echo. Everything works as it should, the variables are set IF the web page name is correct and if I echo out the variables by themselves using
echo "{$p1}, {$p1u}, {$p2}, {$p2u},";
The correct data is shown. I'm obviously doing something wrong in the echo code.
For reference, this is a crude method to inject structured data dynamically.
Either use echo with double quotes "":
echo "<script type=\"application/ld+json\">{\"#context\":\"https://schema.org/\",\"#type\":\"BreadcrumbList\",\"itemListElement\":[{\"#type\":\"ListItem\",\"position\":1,\"name\":\"{$p1}\",\"item\":\"{$p1u}\"},{\"#type\":\"ListItem\",\"position\":2,\"name\":\"{$p2}\",\"item\":\"{$p2u}\"}]}</script>";
or use concatenation:
echo '<script type="application/ld+json">{"#context":"https://schema.org/","#type":"BreadcrumbList","itemListElement":[{"#type":"ListItem","position":1,"name":"' . $p1 . '","item":"' . $p1u . '"},{"#type":"ListItem","position":2,"name":"' . $p2 . '","item":"' . $p2u . '"}]}</script>';
Notice that with double-quotes, you need to escape any other double quote inside the string.
You can use
echo $variable_name //to display the variable
And if you want to display it in a HTML tag then
<p>Your age is <?php echo $age ?>.</p>
Im providing a link for more detailed information
https://www.dummies.com/programming/php/how-to-display-php-variable-values/
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 4 years ago.
$imagefilename=$row['uimage'];
i.e storing the url of an image from table to variable imagefilename
now i wish to use that file name and fetch the image from its location by using the command
echo '<img id="unregistered" src="php/customer/customer_images/{$imagefilename}"/>';
but its not considering "$imagefilename" as a part of the url could some one please tell me how to make this happen thanks!
Append the php variable using single quote like below:
echo '<img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/>';
TRY THIS
<?php
$imagefilename = "file1.jpg";
echo '<img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/>';
echo "\n";
echo "OR";
echo "\n";
$imagefilename = "php/customer/customer_images/file1.jpg";
echo "https://localhost/folderName/update/update.php?$imagefilename";
?>
Here all the Comments in one Answer:
//Your image url
$var = 'my%20text';
// echo with ' and urldecode
echo 'sometext '.urldecode($var).' someothertext';
//lambda function with urldecode
$myfunc = function($text) {
echo urldecode($text);
};
// working echo with {} (needs lambda function)
echo "somtext{$myfunc($var)}";
This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 7 years ago.
Hi I am trying to produce a <td> which also contains an <a> link which will redirect to a function in my controller which also echos the id of my data. Here is my code so far:
<?php
if ($this->session->userdata("username")==$info->U_username) {
echo '<td>EDIT</td>';
}
?>
This code produces an error Disallowed Key characters. Any help or comment is highly appreciated.
For concatenating strings PHP has . operator.
echo '<td>EDIT</td>';
You need to add the result of base_url() to the string you want to output, e.g.:
echo '<td>EDIT</td>';
Either you need to concatinate instead to use php multiple time .use like this
<?php
if ($this->session->userdata("username")==$info->U_username){
echo "<td><a href='".base_url()."'/gamestalker/edit_content/'".$info->C_id."'>EDIT</a></td>";
}
?>
or don't include html into php tags like this
<?php
if ($this->session->userdata("username")==$info->U_username){ ?
<td>EDIT</td>
<? }
?>
You need string concatenation. In PHP you use . for that.
Also codeigniter's base_url can take an argument:
<?php
if ($this->session->userdata("username")==$info->U_username){
echo '<td>EDIT</td>';
}
?>
This question already has answers here:
How to echo php code inside html which is inside php code in this situation? [duplicate]
(2 answers)
Closed 7 years ago.
How can i display form data in echo php ?
My code is:
<?php
echo "<td align='center' style='vertical-align:middle;'> Bust:
<?php
echo $_POST["bust"];
?>
<br> Waist:
<?php
echo $_POST["waist"];
?>
<br> </td>";
?>
But this doesn't work, please guide me with correct steps.
There are a lot of problems with your code.
You're using " in $_POST["bust"] but you opened echo with " as well, causing a conflict.
You're using <?php instead an echo... which is already PHP. There's no need to do this.
It is best to isolate variable printing from your code. Use string concatenation with . as such:
echo "<td align='center' style='vertical-align:middle;'> Bust: ".$_POST["bust"]."<br> Waist: ".$_POST["waist"]."<br> </td>";
This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 8 years ago.
I know this is going to be voted as a bad question but I always have trouble with these.
I am making a php navigation using arrays and my code keeps falling short, mainly in foreach statements. Hopefully if you look you can see where I am trying to go
<html>
<head>
<title>navigation</title>
<?php
$pages = array("index.html" => "Home");
?>
</head>
<body>
<ul>
<?php
foreach($pages as $link => $page){
echo '<li> $page </li>';
}
?>
</ul>
</body>
</html>
$link and $page aren't going to get parsed here, since they're within single quotes:
echo '<li> $page </li>';
Do this instead:
echo '<li> ' . $page . ' </li>';
http://php.net/manual/en/language.types.string.php
Change this:
echo '<li> $page </li>';
To this:
echo "<li> $page </li>";
And you should be good to go.
Check up on strings, particular interpolation
http://php.net/manual/en/language.types.string.php