Page 1 of 1

loss of formating from echo to html

Posted: Mon Jun 16, 2003 7:09 pm
by terence
How do I get the carriage returns in a text file to show up in an html ducument.

Essentially I am writting a text file with a .php extension on it and using the require function to then echo it into an html ducument for online rendering.

The original text document has paragraphs in it- however when it is echoed in html document all the spaces between the paragraphs are lost?

Does any one know how to keep the formating intact?

thanks in advance,
t-

Posted: Mon Jun 16, 2003 9:54 pm
by scH
Instead of "requiring" the file use fopen() and fread() to grab its contents into a string variable, then do a string replace for "\n" and possibly "\r" to "<br />".

Look in the function listings at php.net for both fread and fopen and you should be able to grab most of the code. I'd just write it here, but I'm lazy.

thanks dude!!

Posted: Mon Jun 16, 2003 10:09 pm
by terence
thanks dude!!
I'm in the process of trying this below???


<?php
echo ereg_replace('\r','<br>',$copy);
$CallFunction=WriteToFile
("<tr><td align=\"center\" class=\"title\">".$title."</td></tr>
<tr><td bgcolor=\"#0C2450\"><img src=\"images/cleardot.gif\" height=\"15\"></td></tr>
<tr><td>
<table bgcolor=\"#0C2450\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" width=\"500\">
<tr align=\"center\"><td align=\"left\" width=\"500\" class=\"content\">"
.$copy."
</td></tr>"
);

function WriteToFile($centerCopy){
$TheFile="defaultCopy.php";
$Open=fopen($TheFile, "w+");
fwrite ($Open, "$centerCopy\n");
fclose ($Open);
}
?>

Posted: Tue Jun 17, 2003 8:04 am
by discobean
you should use the nl2br() function instead of the ereg_replace(), that's what its there for :-D

eg.

$br_text = nl2br($text);

ta-da :-D