0

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?

5
  • 1
    paste the output of $img Commented Nov 16, 2017 at 12:39
  • 1
    style needs a = after it Commented Nov 16, 2017 at 12:40
  • 1
    paste the final output of $display too Commented Nov 16, 2017 at 12:40
  • Surely you don't want the backslashes? All the blackslashes do is allow you to use " in your html. 3v4l.org/rRm1Z . As @ProEvilz said, you're missing the = after style and then it should work Commented Nov 16, 2017 at 12:42
  • That fixed it. Thanks for the help! Commented Nov 16, 2017 at 12:44

1 Answer 1

3
$display .= "<p class=\"ey-image-quote\" style=\"background-image:url('".$img."')\">" . $this->quote . "</p>";

You forgot = in style

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

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.