note 35739 added to function.file
| From: | dir at badblue dot php dot net | Date: | Fri, 12 Sep 2003 18:48:02 +0000 |
| Subject: | note 35739 added to function.file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56404@lists.php.net to get a copy of this message | ||
Jeff's array2file function is a good start; here are a couple of improvements (no possibility
of handle leak when fwrite fails, additional capability of both string2file and array2file;
presumably faster performance through use of implode).
function String2File($sIn, $sFileOut) {
$rc = false;
do {
if (!($f = fopen($sFileOut, "wa+"))) {
$rc = 1; break;
}
if (!fwrite($f, $sIn)) {
$rc = 2; break;
}
$rc = true;
} while (0);
if ($f) {
fclose($f);
}
return ($rc);
}
function Array2File($aIn, $sFileOut) {
return (String2File(implode("\n", $aIn), $sFileOut));
}
If you're generating your string text using a GET or POST from a TEXTAREA (e.g., a
mini-web-text-editor), remember that strip_slashes and str_replace of "/r/n" to
"/n" may be necessary as well using these functions.
HTH --dir @ badblue com
----
Manual Page -- http://www.php.net/manual/en/function.file.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35739
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35739&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35739&report=yes