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" />';
Related
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
I'm trying to build a widget for a website that displays a random background image everytime the page is refreshed and i'm running into some trouble with string concatenation.
$display .= "<p class=\"ey-image-quote\" style\"background-image:url('".$img."')\">" . $this->quote . "</p>";
This returns a url without slashes (replaced by spaces) and i have not found a viable solution yet.
Is there any way to achieve this in php?
$display .= "<p class=\"ey-image-quote\" style=\"background-image:url('".$img."')\">" . $this->quote . "</p>";
You forgot = in style
I echo out an image like that:
$newString = $thumbPre.'profilemain'.$thumbPost;
echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>";
Now i want the image as a background-image, i tried it like that, but it doesn´t work:
echo '<div style="background-image:url('http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error');"></div>';
you need to use backslashes for nested apostrophes
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';
Firstly, remove alt='error' because background-image does not have an alt parameter, img does (you probably thought you could use that from your original code). In trying to use that, your background will not show up.
And your background won't show unless you have content inside that div. I've added Content as an example.
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';
You either have to escape the encapsulating quotes, or remove them altogether.
echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';
Error reporting would have also thrown you a parse error such as:
Parse error: syntax error, unexpected '' alt='' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
http://php.net/manual/en/function.error-reporting.php
This is going to look super confusing but you need to 1, escape the quotes and 2, concatenate your path within that,
let me give you an example. I misread a bit of the question but this will serve you well moving forward especially for cleanliness sake
here is an example:
$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';
I have a sentence in PHP that I've broken down into its word components using explode.
foreach ($words as $splitword)
{
echo $splitword;
/* echo "<a href = 'word.php?word=" . $splitword . "'>" . $splitword . "</a>"; */
echo " ";
}
What I want to do is make each word clickable, so I echo each word followed by a space. Now, using the code you see above, everything looks fine and natural. However, if I uncomment the commented line, and comment out echo $splitword;, so that I'm now echoing links instead of just the word, things get ugly:
echo " " no longer works, I have to use echo " "
The spaces are very large. Echoing each word without making it a link produces natural spacing, the way it should be. But when I start using the a tag followed by  , the spaces are about twice as wide.
Any idea why, and what a workaround is?
echo " " does not work because you are writing HTML, which does not parse " ".
You'll have to use like you already discovered.
The extra spacing could be your styling. Check your CSS. If you still don't find anything strange, add this to your CSS:
a {
margin: 0;
padding: 0;
}
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.