CSS formatting with PHP [duplicate]

0

Hello

I'm displaying HTML content with CSS formatting using PHP's print_r, but I'm having doubts when single quotation marks, I've opened STYLE with single quotation marks, but inside the image selection it has 2 single quotes, but not is it working, how do I format it correctly?

<?php print_r("<div value='6_1' style='background-image: url('../img/banner-product.png')'></div>"); ?>
    
asked by anonymous 13.10.2016 / 00:40

3 answers

1

In this case it is not necessary to put the url path with quotation marks can be simply url(../img/banner-product.png) , getting:

print_r("<div value='6_1' style='background-image: url(../img/banner-product.png)'></div>");

another way, could also be:

print_r('<div value="6_1" style="background-image: url(../img/banner-product.png)"></div>');

But you can also escape quotation marks as follows, \" or \' , depends on how the string is involved, whether it is double-quotes or simple. Example:

print_r("<div value='6_1' style='background-image: url(\"../img/banner-product.png\")'></div>");
    
13.10.2016 / 01:22
0

Would not it be something with \" ?

<?php print_r("<div value='6_1' style='background-image: url(\"../img/banner-product.png\")'></div>"); ?>
    
13.10.2016 / 01:05
0

Try to use the scape character: \ '
Use the following code:

<?php echo '<div value="6_1" style="background-image: url(\'../img/banner-product.png\')"></div>'; ?>
    
13.10.2016 / 01:12