Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line Breaks Not Inserted In Exported RTF Document 1

Status
Not open for further replies.

dnayana

Programmer
Nov 14, 2002
53
US
I am exporting content from an MySQL database to a Word Template (RTF) via PHP.

There is a section, "Appendix B", which should display all the Acronyms found for a record. The minimum records to appear for this section is 90 (i.e. these are standard acronyms (tblAcronyms) that each record will have); however the maximum records are unknown since users can add to this listing (tblAppendixB).

The Word (i.e. RTF) document should display all the records found (which it does), however, it is not breaking each record onto its individual line (i.e. line break). (All the content retrieved runs together.)

This is what I have thus far:

Code:
<?php
....

$t_newline = "\r\n";

#Retrieve Appendix B records
$qry_get_AppB = "SELECT vAcronym, vAcronymDesc FROM tblAcronyms
                   UNION SELECT vAcronym, vAcronymDesc FROM tblAppendixB
                     WHERE fkID = ". $i_fk_id . " ORDER BY vAcronym ASC";
$qry_appb_result = mysql_query($qry_get_AppB);
$qryAppBno_rows = mysql_num_rows($qry_appb_result);    

//Generate the headers to help a browser choose the correct location
header('Content-Type: application/msword');
header('Content-Disposition: inline; filename="'.$vProgramName.'_rec.rtf");

//Open the template file
$tfilename = 'Appb_Template.rtf';
$fp = fopen($tfilename, 'r');

//Read the template into a variable
$toutput = fread($fp, filesize($tfilename));

fclose($fp);

//Replace the place holders in the template with data
if($qryAppBno_rows > 0)
{
  while($rowAppB = mysql_fetch_array($qry_appb_result)) 
  {
     $vAppendixB[] = $rowAppB['vAcronym'] . '-' . $rowAppB['vAcronymDesc'] . $t_newline;
     $vAppB = implode($t_newline, $vAppendixB);
  }
}

   $toutput = str_replace('<<vAppB>>', $vAppB, $toutput);

//Send the generated document to the browser
echo $toutput;

?>

Any assistance is greatly appreciated.

Nicole [ponytails2]
 
Hi

Nicole said:
it is not breaking each record onto its individual line (i.e. line break).
Why are you expecting any line break as long there is no [tt]\par[/tt] control code ?

You gave it .rtf extension but the generated content is not RTF. Now what should the poor word processor do with that ?

Feherke.
 
@Feherke,

Didn't know what you were talking about re: "\par"; so I did a little research. Learned that MS Word recognize "\par" as a paragraph mark.

So, I made the following change to my code and it now works.

Code:
   $t_newline = "\par";

   ..... (see above)

   $vAppB = implode(" ", $vAppendixB);

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top