How to send the values to echo? - php

echo "<img src='bloginfo('template_url').'/img/'.$img' />";
i want this value bloginfo must be attach to this src of img tag with $img too...
means how can i adjust this " and ' to get the result.
Please help .

Change it to
echo "<img src='".bloginfo('template_url')."/img/".$img."' />";
And always read manual first before asking question.

Related

cant print images (.svg) of folder using matrix

just print the square but not the image, dont know what is wrong, doesnt throw mistake.
Thanks
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
Nothing wrong in your code. Check if you have correct svg image or not at particular location. (inspect using chrome developer tool)
Check using Object tag or if your browser support or not. https://www.w3schools.com/html/html5_svg.asp
I would recommend to not mix strings with code vars. Always do proper concatenation:
$str = '<img src="/img/' . $numero[$i] . '.svg"';
$str .= ' alt="' . $numero[$i] . '"';
$str .= ' title="' . $numero[$i] . '"';
$str .= ' width="140" height="140">'. "\n";
echo $str;
your code seem right, try checking if the svg image is in the correct image path you placed
i tested with this and is working well
<?php
$numero = array('imagename', 'image alt', 'title');
echo "<img src=\"Images/$numero[0].svg\" alt=\"$numero[1]\" title=\"$numero[2]\" width=\"140\" height=\"140\">\n";
?>
thank you all, I discovered that it happened
I was missing a bar in front of the img
echo "<img src=\"/img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
instead of
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
I do not see any sense

php-how to echo 'get" with the formatting?

I have code like this in php
echo get($contents,'<plaintext>','</plaintext>') ;
it gives me the simple plain text.
Now i want to format this echo text with increase the font size
therefore i try
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>get($contents,'<plaintext>','</plaintext>') </div>";
but it is not working how to do this??
I try this by doing more experiment but none of the things working.
plz help me on this
You need to append the function in the string. Just like this:
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>" . get($contents,'<plaintext>','</plaintext>') . "</div>";

Displaying image from within a php module

I am trying to print the image whose location is saved in my database, I have stored the absolute location in the database and not the relative one , I browsed through a lot of question including this one
include a PHP result in img src tag
I tried all the options that were given to the respective asker of the question but I didn't get my output, rest everything is being displayed apart from the image, its showing no file found
Here's my code, any help will be appreciated
while($result=#mysql_fetch_array($resul,MYSQL_ASSOC)){
$image = $result['image'];
echo $result['company'] . " " . $result['model'] . "<br>" ;
echo '<img src="$image" height="50" width="50" />';
}
I know I am using mysql functions instead of mysqli but this code is not getting live ever.
As watcher said, PHP does not do variable interpolation within single-quoted strings.
The most important feature of double-quoted strings is the fact that variable names will be expanded.
Read more about strings from the PHP manual.
Therefore, when you view the HTML, you will literally see this:
<img src="$image" height="50" width="50" />
Your code should be:
while($result = mysql_fetch_array($resul,MYSQL_ASSOC)) {
$image = $result['image'];
echo $result['company'] . " " . $result['model'] . "<br>";
echo "<img src='$image' height='50' width='50'>";
}
Alternatively, interpolate the array value:
while($result = mysql_fetch_array($resul,MYSQL_ASSOC)) {
echo $result['company'] . " " . $result['model'] . "<br>";
echo "<img src='{$result['image']}' height='50' width='50'>";
}
If the filename contains spaces or other special characters, you may need to use rawurlencode(). In this case, you must concatenate the string since you are calling a function that returns a string value:
echo "<img src='" . rawurlencode($result['image']) . "' height='50' width='50'>";
PHP will not interpolate variables when you include them within single quotes. For more information, see the manual.

IMG SRC Using Path from MySQL and PHP

I have the following line of code which doesn't seem to be working:
echo "<img src='/images/albumart'"; echo $row['art1']; echo "/>";
The 'art1' is definitely returning '/imagename.png' so the URL should be complete however nothing being displayed.
Any ideas?
Thanks.
You really should be concatenating that string:
<?php
echo '<img src="/images/albumart'.$row['art1'].'"/>';
?>
and ideally break out of php to do this:
<img src="/images/albumart<?php echo $row['art1']; ?>"/>
If you're not familiar, the period in php joins strings. That's called concatenation. No need to echo little bits like that, in fact please never do it the way you demonstrate. The root of your issue is, as Geoff pointed out, you weren't closing the src param.
echo "<img src='/images/albumart'"; echo $row['art1']; echo "/>";
It looks like you are closing the img src paramter after the albumart part.,
try this:
echo "<img src='/images/albumart"; echo $row['art1']; echo "' />";

display image in a php function link

i have a question in regards to the following.
i have the function
function print_link($link_num)
{
global $error_str;
if($link_num) {
$error_str .= "<img src='img/Move.png'/>$link_num"
;
}
which displays an image next to a number according to $link_num
i have created a folder with images assigned to this number ($link_num).
im trying to display an image without having the need to display $link_num and the image.
so far ive tried
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src="img/'.$link_num.'.png" />";
but i get an unexpected T_STRING error.
my knowlege of php is not so good, is there a way i can link the image directly from my folder according to $link_num?
i hope ive been clear.
thank you for reading.
You are mixing your " and ' within the code. The first " in the img tag is not being escaped properly and hence caused a parse error on the page try:
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src=\"img/".$link_num.".png\" />";
you have to escape the dot (.) in ".png":
$error_str .= "<a href=\"page.php?toloc=$link_num\"><img src="img/'.$link_num.'\.png" />";
But to make it more clear use only one type of ":
$error_str .= '<a href="page.php?toloc='.$link_num.'"><img src="img/'.$link_num.'.png" />';

Categories