babuno5
asked on
Urgent -- Warning: Cannot modify header information - headers already sent by (output started at C:\PHP Notes\PHPExamples\parserproject\sample6.php:1) in C:\PHP\pear\Writer.php on line 67
Hello
Im always getting the warning cannot modify header info
Actually i m using the Spreadsheet_Excel_Writer-0 .8 in this there is a file called writer.php in which the warnig is pointed
My code is
<?php
require_once 'Writer.php';
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer() ;
// sending HTTP headers
$workbook->send('SampleMon ster.xls') ;
// Creating a worksheet
$worksheet =& $workbook->addWorksheet('M onster1');
$i=0;
$tempState= true;
$filename = "SBC_Monster1.mbx";
$fp = fopen( $filename,"r") or die("Couldn't open $filename");
while ( ! feof( $fp ) ) {
$line = fgets( $fp, 1024 );
if (!preg_match("/(<.html>)/" , $line, $matches))
{
if (preg_match ("/(<\b(FirstName)[^>]*>\b )(.*)(<\/\ \2>)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(LastName)[^>]*>\b) (.*)(<\/\\ 2>)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(Address1)[^>]*>\b) (.*)(<\/\\ 2>)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(City)[^>]*>\b)(.*) (<\/\\2>)/ ", $line, $arTmp))
{
if(!$arEmployee[$i][$arTmp [2]] = "")
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
}
if (preg_match ("/(<\b(StateAbbrev)[^>]*> \b)(.*)(<\ /\\2>)/", $line, $arTmp))
{
if($tempState)
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
$tempState =false;
}
}
if (preg_match ("/(<\b(PostalCode)[^>]*>\ b)(.*)(<\/ \\2>)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(CountryAbbrev)[^>] *>\b)(.*)( <\/\\2>)/" , $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(EmailAddress)[^>]* >\b)(.*)(< \/\\2>)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match ("/(<\b(PhoneType)[^>]*>\b )(.*)(<\/\ \2>)/", $line, $arTmp))
{
//$arEmployee[$arTmp[2]] = $arTmp[3];
if (preg_match ("/(<\b(Number)[^>]*>\b)(. *)(<\/\\2> )/", $line, $arTmp1))
$arEmployee[$i][$arTmp[3]] = $arTmp1[3];
}
if (preg_match ("/(<\b(ContactPreference) [^>]*>\b)( .*)(<\/\\2 >)/", $line, $arTmp))
{
$arEmployee[$i][$arTmp[2]] = $arTmp[3];
}
if (preg_match("/Desired Salary./", $line, $arTmp))
{
$nextline = fgets( $fp, 1024 );
$expSal = strip_tags($nextline);
$arEmployee[$i][$arTmp[0]] = $expSal;
}
}
else
{
//print_r ($arEmployee[$i]);
//print "</BR>";
//print "</BR>";
//print "</BR>";
//print "</BR>";
$i=$i+1;
$tempState= true;
}
}
print $i;
$worksheet->write(0, 0, 'FirstName');
$worksheet->write(0, 1, 'LastName');
for ($j=0;$j<=$i;$j++)
{
foreach ( $arEmployee[0] as $key=>$value ) {
if($key == "FirstName")
{
$worksheet->write($j+1, 0, $value);
}
if($key == "LastName")
{
$worksheet->write($j+1, 1, $value);
}
}
}
//Let's send the file
$workbook->close();
?>
writer.php is
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once('PEAR.php');
require_once('Spreadsheet/ Excel/Writ er/Workboo k.php');
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_W orkbook
{
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_W orkbook The Workbook created
*/
function Spreadsheet_Excel_Writer($ filename = '')
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_W riter_Work book($file name);
}
/**
* Send HTTP headers for the Excel file.
*
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
{
header("Content-type: application/vnd.ms-excel") ; //here is ther problem all five lines are giving warning
header("Content-Dispositio n: attachment; filename=$filename");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0") ;
header("Pragma: public");
}
Thanx in advance
Im always getting the warning cannot modify header info
Actually i m using the Spreadsheet_Excel_Writer-0
My code is
<?php
require_once 'Writer.php';
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer()
// sending HTTP headers
$workbook->send('SampleMon
// Creating a worksheet
$worksheet =& $workbook->addWorksheet('M
$i=0;
$tempState= true;
$filename = "SBC_Monster1.mbx";
$fp = fopen( $filename,"r") or die("Couldn't open $filename");
while ( ! feof( $fp ) ) {
$line = fgets( $fp, 1024 );
if (!preg_match("/(<.html>)/"
{
if (preg_match ("/(<\b(FirstName)[^>]*>\b
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(LastName)[^>]*>\b)
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(Address1)[^>]*>\b)
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(City)[^>]*>\b)(.*)
{
if(!$arEmployee[$i][$arTmp
{
$arEmployee[$i][$arTmp[2]]
}
}
if (preg_match ("/(<\b(StateAbbrev)[^>]*>
{
if($tempState)
{
$arEmployee[$i][$arTmp[2]]
$tempState =false;
}
}
if (preg_match ("/(<\b(PostalCode)[^>]*>\
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(CountryAbbrev)[^>]
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(EmailAddress)[^>]*
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match ("/(<\b(PhoneType)[^>]*>\b
{
//$arEmployee[$arTmp[2]] = $arTmp[3];
if (preg_match ("/(<\b(Number)[^>]*>\b)(.
$arEmployee[$i][$arTmp[3]]
}
if (preg_match ("/(<\b(ContactPreference)
{
$arEmployee[$i][$arTmp[2]]
}
if (preg_match("/Desired Salary./", $line, $arTmp))
{
$nextline = fgets( $fp, 1024 );
$expSal = strip_tags($nextline);
$arEmployee[$i][$arTmp[0]]
}
}
else
{
//print_r ($arEmployee[$i]);
//print "</BR>";
//print "</BR>";
//print "</BR>";
//print "</BR>";
$i=$i+1;
$tempState= true;
}
}
print $i;
$worksheet->write(0, 0, 'FirstName');
$worksheet->write(0, 1, 'LastName');
for ($j=0;$j<=$i;$j++)
{
foreach ( $arEmployee[0] as $key=>$value ) {
if($key == "FirstName")
{
$worksheet->write($j+1, 0, $value);
}
if($key == "LastName")
{
$worksheet->write($j+1, 1, $value);
}
}
}
//Let's send the file
$workbook->close();
?>
writer.php is
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once('PEAR.php');
require_once('Spreadsheet/
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_W
{
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_W
*/
function Spreadsheet_Excel_Writer($
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_W
}
/**
* Send HTTP headers for the Excel file.
*
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
{
header("Content-type: application/vnd.ms-excel")
header("Content-Dispositio
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0")
header("Pragma: public");
}
Thanx in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have removed all spaces from the writer.php which is as follows
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once('PEAR.php');
require_once('Spreadsheet/ Excel/Writ er/Workboo k.php');
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_W orkbook
{
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_W orkbook The Workbook created
*/
function Spreadsheet_Excel_Writer($ filename = '')
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_W riter_Work book($file name);
}
/**
* Send HTTP headers for the Excel file.
*
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
{
header("Content-type: application/vnd.ms-excel") ;
header("Content-Dispositio n: attachment; filename=$filename");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0") ;
header("Pragma: public");
}
.
.
.
.
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once('PEAR.php');
require_once('Spreadsheet/
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_W
{
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_W
*/
function Spreadsheet_Excel_Writer($
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_W
}
/**
* Send HTTP headers for the Excel file.
*
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
{
header("Content-type: application/vnd.ms-excel")
header("Content-Dispositio
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0")
header("Pragma: public");
}
.
.
.
.
The line
print $i;
in the sample file could also do it.
print $i;
in the sample file could also do it.
ASKER
that was just for debugging
anyways removed it but still no result
anyways removed it but still no result
ASKER
thanks a lot for the help the problem is solved
ASKER