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>&acirc;&nbsp;</p>', '&amp;quot;', '&acirc;&nbsp;'), array('', '', '', '', '', '"',''), $dom->savehtml())); 

view page source , check original character replaced with, again replace them original characters using str_replace().


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -