php - Background image from JSON -


alright, have json file stored following,

{      "market_name":"\u2605 bayonet",    "market_hash_name":"\u2605 bayonet",    "icon_url":"\/\/steamcommunity-a.akamaihd.net\/economy\/image\/-9a81dlwlwj2uugcvs_nsvtzdoedtwwkgzzlqhtxdz7i56ku0zwwo4nux4ofjzehlbxu5a1piyqh5hlcx0nvuogsx8ddqbjjiavhubsakqz53p3nzxmxvymykdlsxqwkz7-hkjmivpij3u2y84733gzh_ru_mg_ziyledq45fxiordjh0exf",    "name_color":"8650ac",    "quality_color":"eb4b4b" } 

now using php i'm getting icon_url , i'm trying add background image, since url has these /\/\ won't work background image. how can solve this?

this how i'm trying echo div,

    <div class='image' style='background-image:url('" . $icon . "')'></div> 

edit: work when used <img> i'm soly looking background-image

this full code used:

$getinventory = $db->query('select * `inventories` `user` = '.$db->quote($user['steamid']));         $fetchinventory = $getinventory->fetchall();          $prices = file_get_contents('pricesdb.txt');$prices = json_decode($prices, true);         $images = file_get_contents('iconsdb.txt');$images = json_decode($images, true);          $inventoryarray = array();         foreach ($fetchinventory $key => $value) {             $item = $value['item'];             $id = $value['id'];             $worth = number_format($prices['response']['items'][$item]['value']/100, 2, '.', 1);             $icon;             $rarity;              foreach($images['items'] $key => $value){                             if($value['market_hash_name'] == $item){                                         $icon = $value['icon_url'];                     $rarity = $value['quality_color'];                 }                        }                         $item_wear = preg_replace('/^.*(\(.*\)).*$/', '$1', $item);             $item_wear_short = preg_replace("/(?![a-z])./", "", $item_wear);             $item_rarity = $rarity;              $exp_item_version = explode(" | ", str_replace($item_wear,"", $item));              $item_version = $exp_item_version[0];             $item_name = $exp_item_version[1];              $itemarray = array($id, $icon, $worth, $item_version, $item_rarity, $item_name);              array_push($inventoryarray, $itemarray);         }                 usort($inventoryarray, function($a, $b) {             return $b[2] - $a[2];         });          foreach ($inventoryarray $key => $value) {             $id = $inventoryarray[$key][0];             $icon = $inventoryarray[$key][1];             $worth = $inventoryarray[$key][2];             $item_version = $inventoryarray[$key][3];             $item_rarity = $inventoryarray[$key][4];             $item_name = $inventoryarray[$key][5];              echo "<div class='item'  data-item='" . $id . "'>             <div class='rarity rarity-gold'></div>             <div class='image' style='background-image:url('" . $icon . "')'></div>             <div class='market-name'>             <div class='type'>             " . convert_ascii($item_version) . "             </div>             <div class='name'>             " . $item_name . "             </div>             </div>             <div class='wear'>             fn             </div>             <div class='price'>$" . $worth . "</div>             </div>             ";          } 

here lies problem.

style='background-image:url('" . $icon . "')'

you using single quotes style , url. simple solution.

edit

<div class='image' style='background:url(\"" . $icon . "\")'></div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -