note 35468 deleted from function.file by irchtml
| From: | irchtml@php.net | Date: | Sun, 19 Dec 2004 09:45:14 +0000 |
| Subject: | note 35468 deleted from function.file by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82025@lists.php.net to get a copy of this message | ||
Note Submitter: Jeff
----
<?
/**
* Takes each element of an array and outputs it to the file with filename "$sFilename"
* very much file() in reverse
*
*@param array The array to write to file
*@param string The filename to write out the array to
*
*@return True on success, False on failure
*/
function Array2File( $aryArray, $sFilename ){
//Optimistic execution
$retVal = true;
//Try to open the file
if (!$handle = fopen($sFilename, 'wb+')) {
print "Cannot open file ($sFilename)";
$retVal = false;
}else{
//Convert the array to a string. Each element is one line of the string.
$sArrayAsString = "";
foreach( $aryArray as $thisElement ){
$sArrayAsString .= $thisElement . "\n";
}
//Be good and remove the trailing newline
$sArrayAsString = substr( $sArrayAsString, 0, strlen( $sArrayAsString ) - 1 );
//Write the data to the file
if (!fwrite($handle, $sArrayAsString)) {
print "Cannot write to file ($sFilename)";
$retVal = false;
}else{
//Debug:
//print "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
}
}
return $retVal;
}
?>