将 URL 中的内容编码为 UTF-8,然后转为文件:\

发布于 2024-12-22 12:38:17 字数 731 浏览 1 评论 0原文

我正在使用此代码从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-12-29 12:38:17

首先,确保 iCal 输出在输出时实际上是由服务器编码的 UTF-8。然后您可能需要添加其他标头:

header('Content-type: text/calendar; charset=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:

header('Content-type: text/calendar; charset=utf-8');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文