Does not work, it creates (adds) to every line ending, at every read/save of the text area contents of the file. Read five times, add and saves x5 's to every line.
I’m confused here, then. Are you using print() to display to the
page, or to write into your text file?
Here’s how a form should be used to write into a file:
//set your text variable to nothing
$text = '';
if(isset($_POST['your_textarea'])){
//get the textarea into your variable
$text = trim(strip_tags($_POST['your_textarea']));
if(strlen($text > 0 && $text_file = fopen('yourtextfile.txt',w)){
//open the text file for OVERWRITE
//only if there is something to write
fwrite($text_file,$text,strlen($text));
fclose($text_file);
//redirect to self (clears the form input from the buffer)
header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER
[‘REQUEST_URI’]);
}
}
Then go ahead and read in the file and output it with breaks added to
the newlines. But don’t write the breaks into your file! They’re only
meaningful in the context of HTML, not text.
Does not work, it creates (adds) to every line ending, at
every read/save of the text area contents of the file. Read five
times, add and saves x5 's to every line.
Both, I’m using Print () to populate the textarea, and I think it deletes all content in the file. Then when the form button is pressed the content of the textarea is written to the file.
I’ve amended the code I was originally using to include this:
Which correctly tidies up the display of line feeds of the text.txt file in the textarea.
But…
Just need to do the same in the other web page where the text.txt file is shown as a PHP include. Here the line feed do not appear unless I add back in the textarea edit
How do I convert the text.txt file line ending to meaningful viewable HTML line returns? (without having to write HTML code in the textarea used for editing)
Interestingly as a spin off - this method can be used to edit page title, meta tag, page description etc. By leaving PHP <? print $text; ?> in various places in Freeway (it works by the way although a bit odd having a Freeway Page called <? print $text; ?>). It plugs a gap in WebYep, which lacks these features so far.
This and the other errors you are seeing sound a lot like you have
Mac line-endings on your file, and are running this on a Unix server.
Mac line-endings are rn (return + newline) while Unix line-endings
are simply n (newline).
Actually, Mac is r.
rn is Windows and systems that were designed to drive teletypes.
David
–
David Ledger - Freelance Unix Sysadmin in the UK.
HP-UX specialist of hpUG technical user group (www.hpug.org.uk)
email@hidden www.ivdcs.co.uk