简体   繁体   English

PHP CURL无法使用UTF-8字符

[英]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. 我尝试使用带有PHP CURL请求的api获取蒸汽项,但问题是CURL不支持将UTF-8作为请求。

My PHP Code 我的PHP代码

$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. 只需对URL进行编码,然后再将其与cURL一起使用。

Use urlencode to achieve this task: 使用urlencode完成此任务:

$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";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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