简体   繁体   中英

PHP CURL not working with UTF-8 Character

I try to get steam item using api with PHP CURL request but problem is UTF-8 does not supported by CURL as request.

My PHP Code

$steam_key = $this->config->item("steam_key");
$name = "★ StatTrak™ Bayonet";
echo $url = "http://api.csgo.steamlytics.xyz/v1/prices/$name?key=$steam_key";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
echo $response;

I am getting no any response.

Just encode your URL before using it with cURL.

Use urlencode to achieve this task:

$steam_key = $this->config->item("steam_key");
$name = urlencode("★ StatTrak™ Bayonet"); //Add function call here
echo $url = "http://api.csgo.steamlytics.xyz/v1/prices/$name?key=$steam_key";

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