Jump to content

Internet explorer converting spaces into underscores


joe92

Recommended Posts

Hi, I have a problem with Internet Explorer converting spaces into underscores:

 

The problem occurs using PHPRtfLite.

 

When I run the script I want the file name to contain spaces, however in Internet Explorer these spaces are converted into underscores. This does not happen in ff, chrome, safari or opera.

 

Any help on how to fix this would be much appreciated as I am stuck. Thanks.

Joe

 

p.s.

Here is how the file name is created

$filename = "Mysite - ".$u-ID."' (".$user_name.").rtf";

Below is an example script which when run with the PHPRtfLite library, saves the file with underscores instead of spaces in Internet Explorer (the filename is set at the penultimate line).

 

$name_print=array();
//this is just an example array
for($i=0;$i<10;++$i)
{
	$ii="$i pig";
	$pig=$i*125;
	$name_print[] = array('name'=>$ii,'print'=>$pig);
}

require './library/phprtflite.1.0.1/lib/PHPRtfLite.php';

// register PHPRtfLite class loader
PHPRtfLite::registerAutoloader();
//setting the writing functions
//title
function writeUserInfo($sect,$Myriad_Pro_13,$text0) 
{
    $sect->writeText($text0,$Myriad_Pro_13, new PHPRtfLite_ParFormat());
    
	$sect->writeText('',$Myriad_Pro_14,new PHPRtfLite_ParFormat());
}
//body
function writeGameReports($sect,$Myriad_Pro_14,$Myriad_Pro_12,$name,$report)
{
	$sect->writeText('',$Myriad_Pro_14,new PHPRtfLite_ParFormat());		

	$sect->writeText($name,$Myriad_Pro_14,new PHPRtfLite_ParFormat());

    $sect->writeText($report,$Myriad_Pro_12,new PHPRtfLite_ParFormat());
}
//getting the fonts
$Myriad_Pro_32 = new PHPRtfLite_Font(32, 'Myriad Pro', '#333333');

$Myriad_Pro_14 = new PHPRtfLite_Font(14, 'Myriad Pro', '#000066');

$Myriad_Pro_13 = new PHPRtfLite_Font(13, 'Myriad Pro', '#333333');

$Myriad_Pro_12 = new PHPRtfLite_Font(12, 'Myriad Pro', '#000000');

//title
$text0 = "<i>'Your Descriptions'</i>";

$parFormat = new PHPRtfLite_ParFormat();

//rtf document
$rtf = new PHPRtfLite();
//borders
$borderFormatBlue = new PHPRtfLite_Border_Format(1, '#0000ff');
$borderFormatRed = new PHPRtfLite_Border_Format(2, '#ff0000');
$border = new PHPRtfLite_Border($borderFormatBlue, $borderFormatRed, $borderFormatBlue, $borderFormatRed);
$rtf->setBorder($border);

//headers
$rtf->setOddEvenDifferent();

$header = $rtf->addHeader(PHPRtfLite_Container_Header::TYPE_RIGHT);
$header->writeText("PhpRtf class library. Right document header", $times12, $parFormat);

//section 2
$sect = $rtf->addSection();
//Header overriden
$header = $sect->addHeader(PHPRtfLite_Container_Header::TYPE_RIGHT);
$header->writeText("GAMES", $Myriad_Pro_32, $parFormat);
//Borders overriden: Green border
$border = PHPRtfLite_Border::create(1, '#00ff00', 'dash', 1);
$sect->setBorder($border);

//function set in line 11
writeUserInfo($sect,$Myriad_Pro_13,$text0);

//using function set in line18
foreach($name_print AS $element) 
{
	$named = $element['name'];
	$report = $element['print'];
    	writeGameReports($sect,$Myriad_Pro_14,$Myriad_Pro_12,$named,$report);
}

// send to browser
$filename = "Game - report.rtf";

$rtf->sendRtf($filename);

 

I also have an almost identical script which outputs in open office format which also has the same problem. I need the spaces in, is there a way around this?

    public function sendRtf($file = 'simple') {
        $this->prepare();

        $pathInfo = pathinfo($file);

        if (empty($pathInfo['extension'])) {
            $file .= '.rtf';
        }

        if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 5.5')) {
            header('Content-Disposition: filename="' . $file . '"');
        }
        else {
            header('Content-Disposition: attachment; filename="' . $file . '"');
        }
        header('Content-type: application/msword');
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: public");

        echo $this->_content;
    }

 

The above is the sendRtf funtion found in the PHPRtfLite.php

 

I've also attached the whole script if you would like to look at the whole thing.... (the above section starts on line 841)

 

[attachment deleted by admin]

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.