I want to write php in a style tag but I dont know how. Now I am stuck with this :
echo"<div class='fill' style='background-image:url('upload/".$row['file1']."');'></div>";
But in the browser it shows like this :
<div class="fill" style="background-image:url(" upload="" test.png');'=""></div>
Can someone help me?
The problem is that you're using '
as both the delimiter around the style
attribute's value and around the URL inside the parentheses. The second '
is ending the value. URLs inside a url(...)
style don't need to be quoted, so you can just write:
echo "<div class='fill' style='background-image:url(upload/".$row['file1'].");'></div>";
This has nothing to do with PHP.
You have an HTML attribute value that you are delimiting with '
characters.
You are trying to use a '
inside it as data.
It terminates the attribute value instead of representing a quote mark.
Replace it with a character reference: '
swap your '
with your "
, or you can escape your quotes
echo '<div class="fill" style="background-image:url(upload/' . $row['file1'] . ');"></div>';
Or use backslash to escape quotes
echo"<div class='fill' style='background-image:url(\'upload/".$row['file1']."\');'></div>";