?
Solved

PHP output file producing empty lines

Posted on 2008-11-02
11
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 300 total points
ID: 22861208
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
ID: 22861745
Post your code here if you dont mind or attach a file so we can see
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 900 total points
ID: 22862643
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Assisted Solution

by:ahalya
ahalya earned 300 total points
ID: 22863797
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
ID: 22864726
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
 
LVL 1

Author Comment

by:kalmen
ID: 22865439
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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 900 total points
ID: 22867261
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
ID: 22873259
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
ID: 31512465
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
ID: 25312667
This is incredibly helpful!  I have been searching for how to do this!
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 25315961
"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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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.
Suggested Courses

752 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