Solved

PHP output file producing empty lines

Posted on 2008-11-02
11
585 Views
Last Modified: 2013-12-13
Hello,

I'm writing code to produce an ICS file. The code I'm writing looks like this:

<?php
// Define the file as an iCalendar file
header("Content-Type: text/Calendar");
// Give the file a name and force download
header("Content-Disposition: inline; filename=aus_events.ics");
?>

I then continue my code as normal to produce the contents of the file.

For some reason I get blank lines at the top of my file that sum the total number of records, and I checked the loop for any blank files being generated, but there are none.

I'm putting the whole output in one variable so I can remove any blank lines:
<?php
//END FOOTER
$ics_file .="END:VCALENDAR";
$ics_file = trim($ics_file);
echo $ics_file;
?>

But still haven't figured that out. Any help would be appreciated.
0
Comment
Question by:kalmen
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 100 total points
Comment Utility
Ensure that there are no blank lines before your first <?php tag and none after the last ?> tag. If you include any other PHP files then check them as well for blanks before and after the <?php and ?> tags
0
 
LVL 19

Expert Comment

by:NerdsOfTech
Comment Utility
Post your code here if you dont mind or attach a file so we can see
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 300 total points
Comment Utility
Try using something like this... You will find some local functions that look like "pidgin" code, but you should be able to follow the logic and transfer it to your own uses.  I've used this structure on several web sites with a strong record of success.  Best of luck, ~Ray
<?php // vcal_generator.php

$config_page= getcwd() . '/_config.php'; require_once($config_page);
 

// GET THE KEY OF THE TOURNAMENT

$t_key	= get_clean_numeric_string($_GET[t]);

if (!is_numeric($t_key)) { die("Error T"); }
 

// COLLECT THE TOURNAMENT DATA

$tsql	= "SELECT * FROM {$my_dbt_prefix}_TOURNAMENTS WHERE _key = $t_key LIMIT 1";

if (!$t	= mysql_query("$tsql", $db_connection)) { non_fatal_query_error($tsql); die(); }

if (!$t_rows= mysql_num_rows($t)) { die("Error T=$t_key"); }

$trow	= mysql_fetch_assoc($t);

foreach ($trow as $k => $v) { $$k = stripslashes($v); } //<
 

// COLLECT THE SERIES/CIRUCIT DATA

$csql	= "SELECT * FROM {$my_dbt_prefix}_SERIES WHERE _key = $c_key LIMIT 1";

if (!$c	= mysql_query("$csql", $db_connection)) { non_fatal_query_error($csql); die(); }

if (!$c_rows= mysql_num_rows($c)) { die('Error C=$c_key'); }

$crow	= mysql_fetch_assoc($c);

foreach ($crow as $k => $v) { $$k = stripslashes($v); }
 

// FORMAT THE START AND FINISH DATES AND TIMES FOR HUMAN-READABLE

$p_date		= date('l, F j, Y', strtotime($date));

$p_start	= date('g:ia', strtotime($start));

$p_finish	= date('g:ia', strtotime($finish));

$my_start	= date('D, M j, Y g:ia', strtotime($p_date .' '. $p_start));
 

// FORMAT THE START AND END TIMES FOR VCAL

$vcalstart	= date("Ymd", strtotime($date)) .'T'. date("His", strtotime($start));

$vcalend	= date("Ymd", strtotime($date)) .'T'. date("His", strtotime($finish));
 

// FORMAT THE OTHER INFORMATION FOR THE VCAL

$summary	 = "Bass Tournament: $p_date";
 

// FORMAT THE INFORMATION FOR THE BODY OF THE CALENDAR ENTRY

$dump		 = "";

$dump		.= "$year $name" . "=0D=0A";

$dump		.= "Mark your calendar for $my_start" . "=0D=0A";

if ($launch != "") { $dump .= "Launch: $launch" . " =0D=0A"; }

if ($title  != "") { $dump .= "$title" . " =0D=0A"; }

$dump		.= "http://www.BassTournamentURL.com" . "=0D=0A";
 

$filename = "BassTournament" . $t_key . ".vcs";
 

header("Content-Type: text/x-vCalendar");

header("Content-Disposition: inline; filename=$filename");
 

?>

BEGIN:VCALENDAR

VERSION:1.0

PRODID:Bass Tournament Web Calendar

BEGIN:VEVENT

SUMMARY:<?php echo "$summary\n"; ?>

DESCRIPTION;ENCODING=QUOTED-PRINTABLE: <?php echo "$dump\n"; ?>

DTSTART:<?php echo "$vcalstart\n"; ?>

DTEND:<?php echo "$vcalend\n"; ?>

END:VEVENT

END:VCALENDAR

Open in new window

0
 
LVL 7

Assisted Solution

by:ahalya
ahalya earned 100 total points
Comment Utility
A common problem is the character set used by your text editor (and Apache, PHP).  For example your php file may be unicode, and the web server/php may be set to work with ASCII.

Save your PHP file as a single-byte ASCII text and see whether it helps. (Most editors allow such
0
 
LVL 1

Author Comment

by:kalmen
Comment Utility
I'm going to check all the answers asap. I just thought that I should note that I'm using Adobe Dreamweaver CS3, and I have be experiencing loads of PHP related development problems, specifically with Apache2/PHP5 while I have an older server Apache1/PHP4 that seems okay.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:kalmen
Comment Utility
NerdsOfTech: Sorry, the code has too much information that masking it will render it useless for troubleshooting.

The same code runs without any problem on Apache1/PHP4.

I think my server might not be configured properly?

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 300 total points
Comment Utility
You might want to be on the lookout for the settings of "register globals" -- and there may be some other things that can trip you up in switching from PHP4 to PHP5.  If you want some help on the transition, you might want to post a question about that in the PHP section.  When you post that question, put in a link to your phpinfo() script on each of the machines.

The code I posted above has worked correctly since the late 1990's, although I have not yet tested it on PHP6.  Have you tried it on PHP4 or PHP5 yet?

 Best regards, ~Ray
0
 
LVL 1

Author Comment

by:kalmen
Comment Utility
Hi Ray,

I'm grateful for the input that all colleagues have contributed in this post, it has helped me find the cause of this problem.

I will do this post for the upgrade, and I want to point out that the problem was eliminated when I changed my include from:

virtual('../../Connections/web.php') to
require_once('../../Connections/web.php')

But I can't really understand the reason for this. As it works perfectly with Apache1/PHP4 but with my Apache2/PHP5, I think a post for this will be necessary.

Thank you.
0
 
LVL 1

Author Closing Comment

by:kalmen
Comment Utility
Thanks for your help. Your answers helped me identify the problem, which I believe is better suited for another question.

Thanks.
0
 
LVL 2

Expert Comment

by:JGoyer
Comment Utility
This is incredibly helpful!  I have been searching for how to do this!
0
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
"virtual" only works where PHP is installed as an Apache module. If PHP is installed as FastCGI or any other method then the "virtual" directive will fail.

Virtual spawns Apache subprocesses. If all you really want to do is include files then stick to "include" or "require" - they are a lot more portable.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now