loss of formating from echo to html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
terence
Forum Newbie
Posts: 21
Joined: Fri Jun 06, 2003 11:31 pm
Location: new york city

loss of formating from echo to html

Post 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-
scH
Forum Newbie
Posts: 5
Joined: Mon Jun 16, 2003 11:48 am
Contact:

Post 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.
terence
Forum Newbie
Posts: 21
Joined: Fri Jun 06, 2003 11:31 pm
Location: new york city

thanks dude!!

Post 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);
}
?>
User avatar
discobean
Forum Commoner
Posts: 49
Joined: Sun May 18, 2003 9:06 pm
Location: Sydney, Australia
Contact:

Post 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
Post Reply