View Full Version : CSS style written by PHP doesn't work!

01-20-2012, 02:07 AM
Hi, experts, help please, thank you so much.

I wrote css style for an image by PHP, as follows:

<img src="<?php echo "/images/prizes/".$_SESSION['imgForPrizes'][$key1]; ?>" >

It's working , and fine.

However, if I want the image as a background, and wrote as below:

<.... style="background:url(“<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>”) no-repeat center; ">

It's not working, the image doesn't show on the web page.

Could experts help me to sort the problem out?

Thank you!

01-20-2012, 02:38 AM
Are the invalid characters in “<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>” actually there or are they really " that have been accidentally converted to invalid characters when you copied them to the forum?

If they are actually " and not invalid angled quotes then have you tried viewing the source of the page to see what code is being generated by the PHP when someone views the page?

01-20-2012, 02:44 PM
Felgall, thanks,

I've sort it out, by removing " " between ( and <, then it is working.

<.... style="background:url(<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>) no-repeat center; ">