简体   繁体   中英

PHP Echo Inline CSS

I would like to set an inline css background image using a variable using a PHP echo.

echo "<div id='wtile' style='background:url(\'http://cdn.steamcommunity.com/economy/image/". $row["icon_url_large"]. "\');'> 
    <div id='name'> ". $row["market_hash_name"]. "</div> 
    <div id='price'> ". $row["avg_price_7_days"]. "</div>
    </div>";

I tried this, does not seem to work. TIA

The problem seems to be strictly within the first div . Try changing it to this:

"<div id='wtile' style='background:url(http://cdn.steamcommunity.com/economy/image/". $row["icon_url_large"] . ");'> [...other divs]

Quoting the url value is optional and seems to be only making the code more confusing in this case.

EDIT:

Also, I accessed the link you provided in the comments and the values in $row["icon_url_large"] look really odd and don't even seem to have an extension (eg png). Make sure they refer to valid image files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM