将 URL 中的内容编码为 UTF-8,然后转为文件:\
我正在使用此代码从 icloud 获取我的日历之一。这是一个转变成下载文件的网址(应该是 *.ics,但我可以不带它离开)。问题是该文件是 ANSI。我希望它以 UTF-8 格式下载。
<?php
$file = "http://p04-calendarws.icloud.com/ca/subscribe/1/xxxzzzccc".$_GET['file']."";
header( "Content-Disposition: attachment; filename=".basename($file));
@readfile($file);
?>
谢谢
编辑:
所以,我尝试了一条不同的路:
<?php
$url = 'http://p04-calendarws.icloud.com/ca/subscribe/1/xxxzzzccc';
$img = 'z.ics';
file_put_contents($img, file_get_contents($url));
$utfconvert = file_get_contents("z.ics");
$saveit = fopen("zz.ics","w");
fwrite($saveit,utf8_encode($utfconvert));
fclose($saveit);
?>
但新文件保存时没有 bom,并且谷歌日历仍然没有显示正确的字符。我已经花了 3 个小时在这上面并且还在计数。
i'm using this code to get one of my calendars from icloud. It's a url that turns into a file for download (should be *.ics but i can leave without it) . the problem is that the file is ANSI. i want it to be downloaded as UTF-8.
<?php
$file = "http://p04-calendarws.icloud.com/ca/subscribe/1/xxxzzzccc".$_GET['file']."";
header( "Content-Disposition: attachment; filename=".basename($file));
@readfile($file);
?>
Thanks
EDIT:
so, i tried a different road :
<?php
$url = 'http://p04-calendarws.icloud.com/ca/subscribe/1/xxxzzzccc';
$img = 'z.ics';
file_put_contents($img, file_get_contents($url));
$utfconvert = file_get_contents("z.ics");
$saveit = fopen("zz.ics","w");
fwrite($saveit,utf8_encode($utfconvert));
fclose($saveit);
?>
but the new file is saved without bom and google calendar STILL doesn't show the right characters. I've spend 3 hours on this and counting.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,确保 iCal 输出在输出时实际上是由服务器编码的 UTF-8。然后您可能需要添加其他标头:
First, make sure that the iCal output is actually UTF-8 encoded by the server when you output it. You then may want to add additional headers: