嗨,我想读网页网址的内容,里面有日语单词。
我的现有代码如下所示
$url = "http://fantasticlife稼ぐ777.tokyo" ;
$responseText = "";
try {
$responseText = @file_get_contents($url);
var_dump($responseText);
} catch (\Exception $e) {
echo $e->getMessage();
}我得到了后续输出。
bool(false)我关心的是事情哪里出了问题。上面的代码对于普通的urls很好。
提前谢谢。
发布于 2014-12-29 08:22:18
谢谢,通过将域名转换为IDNA ASCII表单完成。ascii()函数代码片段如下所示。
if (strpos($url,"http://")!== false){
$url = "http://" . idn_to_ascii(str_replace("http://", "",$url));
}else if(strpos($url,"https://")!== false){
$url = "https://" . idn_to_ascii(str_replace("https://", "",$url));
}else{
$url = idn_to_ascii($url);
}再次感谢。:)
https://stackoverflow.com/questions/27683711
复制相似问题