php - Weird characters show up -
i trying fetch prices steam market, works well, , returning array, there 1 problem. cs:go items such stattrak items or knives have either star (★
or how valve sends "\u2605
") or trademark logo (™
or how valve sends "\u2122
")
my array doesn't see them these characters, convert instead:
â stattrak⢠karambit | damascus steel (field-tested)
but should be:
★ stattrak™ karambit | damascus steel (field-tested)
this how fetch info:
$url = "https://steamcommunity.com/market/search/render/?query=&start=0&count=99&&search_descriptions=0&sort_column=price&sort_dir=popular&appid=730&category_730_itemset%5b%5d=any&category_730_proplayer%5b%5d=any&category_730_stickercapsule%5b%5d=any&category_730_tournamentteam%5b%5d=any&category_730_weapon%5b%5d=any"; $html = file_get_contents($url); $html = json_decode($html, true); $html = $html['results_html']; $dom = new domdocument; @$dom->loadhtml($html); $xpath = new domxpath($dom); $itemname = $xpath->query('//span[@id="result_' . $q . '_name"]'); $itemprice = $xpath->query('//*[@id="result_' . $q . '"]/div[1]/div[2]/span[1]/span[1]');
in loop, ofcourse, shouldn't matter right now. $q
in range 0-99.
how go getting contents proper characters?
use following code replace special characters original characters.
$itemprice = preg_replace('/^<!doctype.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>', '<p>â </p>', '&quot;', 'â '), array('', '', '', '', '', '"',''), $dom->savehtml()));
view page source , check original character replaced with, again replace them original characters using str_replace()
.
Comments
Post a Comment