joe92 Posted January 17, 2011 Share Posted January 17, 2011 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"; Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/ Share on other sites More sharing options...
Maq Posted January 17, 2011 Share Posted January 17, 2011 We need more information. Some relevant code, how this has to do with the browser, an example of what's going on, etc... Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1160792 Share on other sites More sharing options...
joe92 Posted January 18, 2011 Author Share Posted January 18, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1161350 Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 Sorry I'm not familiar with the PHPRtfLite class. Can you post the 'sendRtf()' method? Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1161354 Share on other sites More sharing options...
joe92 Posted January 18, 2011 Author Share Posted January 18, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1161359 Share on other sites More sharing options...
joe92 Posted January 19, 2011 Author Share Posted January 19, 2011 Does Internet Explorer replace spaces with underscores with all downloads? Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1161977 Share on other sites More sharing options...
joe92 Posted February 15, 2011 Author Share Posted February 15, 2011 UPDATE: I have noticed that this happens in Windows 7 but not in Windows XP. Have not been able to test Apple or Linux based operating systems, yet. Has anybody else heard of this? Quote Link to comment https://forums.phpfreaks.com/topic/224727-internet-explorer-converting-spaces-into-underscores/#findComment-1174542 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.