这是我的代码:
file_put_contents('ip.txt', $ip); // ip is 62.227.217.95 and is saved correctly into ip.txt file
$returned_content = get_data('https://xxx:[email protected]/geoip/v2.1/city/' . $ip);
file_put_contents('content.txt', $returned_content); // file is empty, nothign saved
您可以在评论中看到问题所在。
但是当我直接放入ip而不是GET参数时:
file_put_contents('ip.txt', $ip); // ip is 62.227.217.95 and is saved correctly into ip.txt file
$returned_content = get_data('https://xxx:[email protected]/geoip/v2.1/city/62.227.217.95');
file_put_contents('content.txt', $returned_content); // content is written correctly, everything fine.
我在这做错了什么?我也试过urldecode($ip)
请帮忙
尝试
get_data('https://xxx:[email protected]/geoip/v2.1/city/'.$ip.'');
要么
$url = 'https://xxx:[email protected]/geoip/v2.1/city/'.$ip;
get_data($url);
有隐形的字符,我解决了它:preg_replace('/[\x00-\x1F\x7F]/u', '', $ip)