Echo does not return the image path in the HTML "style" attribute

Asked

Viewed 32 times

0

I did the following

echo"<div class='carousel-item active' style='background-image: url('img/intro-carousel/". $row["img_pag_princ_car"] . "')>"

But the following is returning:

<div class="carousel-item active" style="background-image: url(" img="" intro-carousel="" 01_gigaclima_indoor.jpg')="">

What am I doing wrong? Why are you replacing the / for ?

  • Better [Dit] and post a better context of your application. It may be some template engine, something dealing with the output buffer, some configuration, framework acting in another part of the code (otherwise the quotes would not be changed in the output). The way it is, just with what you have in the question, you can’t reproduce the problem. We need more details or a [mcve]. - And to make matters worse, you are using simple quotes incorrectly in the HTML part, a good start would be to fix this (applying to the style and to the url inside style).

  • There’s something strange. In your code you have class='carousel-item active' and on the way out class="carousel-item active", Either the output is not from this code or this is not the only code that is generating this output.

  • the problem is that here url(' quote closes the attribute style, so the mistake, but not quite sure how to fix, tries to escape with so: url(\" ... \") double-quote

1 answer

2


The problem is the quotation marks, you are getting lost in the interpolation. Try to escape the quotation marks:

echo  "<div class=\"carousel-item active\" style=\"background-image: url('img/intro-carousel/". $a . "')\">";
  • That’s right, thanks for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.