Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:56:14+00:00 2026-06-12T03:56:14+00:00

I need your help. I’m writing a iCal .ics File-format with a php function.

  • 0

I need your help. I’m writing a iCal .ics File-format with a php function.

If I open the .ics file with iCal it says the application says: “Calendar can’t read this calendar file. No events have been added to your calendar.”

However if I validate the file with an online .ics validator it says everything should be fine except the line endings. The validator says this:

Your calendar is using an invalid newline format. Make sure to use
\r\n to end lines rather than just \n (RFC 2445 §4.1).
Congratulations; your calendar validated!

But I’m not sure if this is the “real” problem why my iCal can’t read the file.
First off, I wonder how to change this line endings?

<?php

function wpse63611_events_feed_output(){
    $filename = urlencode( 'My-Events-' . date('Y') . '.ics' );

    // Start collecting output
    ob_start();

    header( 'Content-Description: File Transfer' );
    header( 'Content-Disposition: attachment; filename=' . $filename );
    header( 'Content-type: text/calendar' );
    header( "Pragma: 0" );
    header( "Expires: 0" );
?>
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//<?php  get_bloginfo('name'); ?>//NONSGML Events //EN
CALSCALE:GREGORIAN
X-WR-CALNAME:<?php echo get_bloginfo('name');?> - Events
<?php
    if ( have_posts() ):
        $now = new DateTime();
        $datestamp =$now->format('Ymd\THis\Z');
        while( have_posts() ): the_post();
            global $post;
            $uid = md5(uniqid(mt_rand(), true))."@mydomain.com";
            $start = unixToiCal(get_event_date($post, true, true), 2.0);
            $end = unixToiCal(get_event_end_date($post, true, true), 2.0);
            $summary = wpse63611_esc_ical_text(get_the_title());
            $description = apply_filters('the_excerpt_rss',  get_the_content());
            $description = wpse63611_esc_ical_text($description); ?>
BEGIN:VEVENT
UID:<?php echo $uid; ?>
<?php echo "\r\n"; ?>
DTSTAMP:<?php echo $datestamp; ?>
<?php echo "\r\n"; ?>
DTSTART:<?php echo $start; ?>
<?php echo "\r\n"; ?>
DTEND:<?php echo $end; ?>
<?php echo "\r\n"; ?>
SUMMARY:<?php echo $summary; ?>
<?php echo "\r\n"; ?>
DESCRIPTION:<?php echo $description; ?>
<?php echo "\r\n"; ?>
END:VEVENT
<?php endwhile; endif; ?>
END:VCALENDAR
<?php
    // Collect output and echo 
    $eventsical = ob_get_contents();
    ob_end_clean();
    echo $eventsical;
    exit();
}

function unixToiCal( $uStamp = 0, $tzone = 0.0 ) {
    $uStampUTC = $uStamp + ($tzone * 3600);       
    $stamp  = date("Ymd\THis\Z", $uStampUTC);
    return $stamp;       
}

function wpse63611_esc_ical_text( $text='' ) {
    $text = str_replace("\\", "", $text);
    $text = str_replace("\r", "\r\n ", $text);
    $text = str_replace("\n", "\r\n ", $text);
    return $text;
}

?>

Can you see any problem with this? What could cause the calendar not to work?


UPDATE
Well, I fixed the line endings and the calendar validates fine now. So no errors when validating it, but I still can’t get it working in iCal. When I open it it still says the calendar file is not readable. Here is the actual file that is generated by my script … http://cl.ly/383D3M3q3P32

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:56:16+00:00Added an answer on June 12, 2026 at 3:56 am

    looking at your ical file brings 2 topics:

    1. as mentionned above, all your lines need to be ended by \r\n (i.e. you need to ensure

    BEGIN:VCALENDAR

    VERSION:2.0

    ..

    are also ended properly

    2.you need to escape commas in text (see RFC5545 §3.3.11: https://www.rfc-editor.org/rfc/rfc5545#section-3.3.11 )

    you can also run those through online icalendar validators see this post answer: https://stackoverflow.com/a/4812081/1167333

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need your help! How do I in my application to call the function only
I need your help. I tried to play an audio file stored in Assets
I need your help. I'm trying to install php_apc.dll into my php directory. So
Need your help with my PHP/MYSQL array. I have a php script that selects
I need your help :( I'm working on a iOS application in which i
I need your help please. I have this xml file which I need to
Need your help, trying to change this script: https://github.com/MrHus/jquery-monthly-ical To load external JSON data
need your help with PHP templating. I'm new to PHP (I'm coming from Perl+Embperl).
I need your help! In my application, strange behavior when displaying images in GridView
I'm a beginner and I really need your help! I have an XML file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.