1

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?

0

4 Answers 4

3

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: &#039;

Sign up to request clarification or add additional context in comments.

Comments

1

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>";

1 Comment

URLs inside a url(...) style don't need to be quoted only if there's no white-space in the URL.
0

swap your ' with your ", or you can escape your quotes

echo '<div class="fill" style="background-image:url(upload/' . $row['file1'] . ');"></div>';

Comments

0

Or use backslash to escape quotes

echo"<div class='fill' style='background-image:url(\'upload/".$row['file1']."\');'></div>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.