Format CSS with PHP

Asked

Viewed 425 times

0

Hello

I’m displaying an HTML content with CSS formatting using PHP print_r, but I’m having doubts when the simple quotes, I opened the STYLE with simple quotes, but inside the image selection has 2 simple quotes too, but it’s not working, how I shape it correctly ?

<?php print_r("<div value='6_1' style='background-image: url('../img/banner-product.png')'></div>"); ?>
  • try using echo instead of print_r

3 answers

1


In this case it is not necessary to put the url path with quotes can simply stay 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 the quotation marks as follows, \" or \', depends on how the string is wrapped, whether it is double or single quotes. Example:

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

0

It wouldn’t be something with \" ?

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

0

Try using the scape character: \'
Use the following code:

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

Browser other questions tagged

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