nl2br converts each newline to a break plus a newline. htmlspecialchars converts any characters that have special meaning
to HTML into entity escapes, so they don’t mess with the rest of your
layout. implode with an empty delimiter means convert this array into a
string, inserting nothing between each element of the array. file means read the named file, converting it into an array, broken
into elements at each newline.
Now it occurs to me as I write this, that what you really want is
this, which is much simpler:
The whole business of converting the file into an array and then
right back into a string is a total waste of cycles. file_get_contents is a very memory-conservative way to read an
entire text file into a variable. It is highly tuned and very very
fast on every platform PHP runs on, and can open files up to the
limit imposed on PHP by your system administrator. I use it on the
Online Library of Liberty to read in up to 20MB XML files before
parsing them to XHTML and then SQL.
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).
Try changing the line-endings on your form processor script, and also
on your Freeway page.
On Jan 21, 2008, at 7:51 AM, dwn wrote:
If you test this code in a PHP file called processscript.php and
$fn = "text.txt";
$fn = "text.txt";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file in write mode!");
fclose($fp) or die ("Error closing file!");
Note how when the text area is generated, there is a space then
line return already present. How can I remove this so it is totally
(refer to the text.txt file generated - this is blank)
In Freeway, you select Document Preferences from the File menu, and
change it in the Output tab. If you are using a programmer’s text
editor, like TextMate or BBEdit, there will be a document-by-document
preference, usually in the main menu somewhere, to set the line-
endings for the currently open document.
I’ve changed in Freeway, (and checked with on line with text wrangler - on unix hosting line feed are unix LF) and the mysterious “space then line return” in still being created when the textarea is created from the PHP file (exactly same behavior)
There must be something in the PHP that is creating the space-line return in the textarea content when the code writes the page code.
Trouble is, I don’t know what it is thats doing it.