Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 648
  • Last Modified:

PHP output file producing empty lines

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
kalmen
Asked:
kalmen
  • 4
  • 2
  • 2
  • +3
4 Solutions
 
Beverley PortlockCommented:
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
 
NerdsOfTechTechnology ScientistCommented:
Post your code here if you dont mind or attach a file so we can see
0
 
Ray PaseurCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ahalyaCommented:
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
 
kalmenAuthor Commented:
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
 
kalmenAuthor Commented:
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
 
Ray PaseurCommented:
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
 
kalmenAuthor Commented:
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
 
kalmenAuthor Commented:
Thanks for your help. Your answers helped me identify the problem, which I believe is better suited for another question.

Thanks.
0
 
JGoyerCommented:
This is incredibly helpful!  I have been searching for how to do this!
0
 
Beverley PortlockCommented:
"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

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.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now