View Full Version : trouble with line breaks in php include HELP!
kathari
April 29th, 2004, 05:23 PM
Hi,
I am making a news section on my site which is only a pop-up window with a table in it. To make my client update it by himself I have made a txt-file and use php to include it.
I have also used the <pre> tag around the code to keep the formatting of the .txt.
This works fine except that in Explorer the line breaks disappear. Since the pop-up is chromeless and fairly small it is a real problem. In Netscape and Safari it works fine. the only way I can make it work so far is to type the <br> tag in the txt-file and take away the <pre>. But I can't really make my client do that. Besides not knowing anything about html it's kind of difficult to estimate when to make the line breaks...
Does anyone know how to solve this? :pa:
<?PHP include ("news.txt"); ?>
Unit
April 29th, 2004, 05:32 PM
So does your client have a text box which he can use to write content to the text file? If so, then you could just use nl2br($text) before the content is submitted.
kathari
April 29th, 2004, 05:40 PM
The idea would be that he adds text to the "news.txt". so I guess no, I don't know much about this but I would love to learn...
Lost
April 30th, 2004, 03:10 AM
nl2br...
New Line to Break.. every line it adds a break..
you would use..
nl2br(readfile("news.txt"); // i think.. Also. if you set it to a variable it will return the bytes... I cant remember the command to open a file and you can use a foreach command and read each line...
kathari
April 30th, 2004, 04:05 AM
THanks for an answer! However I am lost and definitely NOT a technical artist.
I tried putting in your script right after my include code but it returns a Parse error message saying unexpected ";" in line 12. When I try to take away that ; I get a new message saying the same thing about line 13. Only in line thirteen I only have the closing ?>.... I guess I am adding it wrong.
Here is the code for the entire page.php:
<BODY leftmargin="0" topmargin="0">
<table width="304" height="420" class="tabell">
<tr>
<td align="left" valign="top"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><?PHP
include ("news.txt");
nl2br(readfile("news.txt");?></font></td>
</tr>
</table>
</BODY>
</HTML>
Lost
April 30th, 2004, 04:22 AM
hehe.... hold on ill help ya out..
kathari
April 30th, 2004, 04:24 AM
THANK YOU
The horrible thing about being self taught is that you always, always end up realizing how little you know. (however it'sfun when it works though...)
Lost
April 30th, 2004, 04:32 AM
Alright
<?php
readfile("news.txt");
?>
this will read your text out in one straight line regardless if you put a "enter" key in the text.
now lets look at the file function getting each line into an array and outputing each line:
<?php
$textline = file("news.txt"); //set a variable and make it an array to hold each line
foreach($textline as $showline){ //foreach line in textline set it to a new variable
echo $showline . "<br>"; //display the line and create a new line
}
?>
This would read each line of the file and add a new line after each line.
Using include is way different then readfile and file funtion. Lets say you had the header of your website called header.html and you wanted to put it on each of your pages so you didnt have to copy and paste all the code into each of your pages you could use:
include("header.html");
That would display header.html first and then whats ever in your body would come after..
Hope this helps
kathari
April 30th, 2004, 04:42 AM
THANKS! It works in safari and Explorer and I do understand what it means (doing it by myself is another issue... will take time for that sometimes) However again, in Netscape it only displays the last comment, like this:
" ;//display the line and create a new line } ?>
Any ideas?
Lost
April 30th, 2004, 04:47 AM
<?php
$textline = file("news.txt");
foreach($textline as $showline){
echo $showline . "<br>";
}
?>
try that
kathari
April 30th, 2004, 06:18 AM
Hm i can't see the difference between the two codes... unless you mean taking away the comments. It does work now though... I checked again when I saw this.
i tried fixing something before, I can't remember exactly what, a space between signs or something maybe that's why. I'll look into it later, have to run.
But THANKS AGAIN!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.