note 67835 deleted from function.file by bjori
| From: | bjori@php.net | Date: | Wed, 05 Jul 2006 21:12:30 +0000 |
| Subject: | note 67835 deleted from function.file by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114426@lists.php.net to get a copy of this message | ||
Note Submitter: steve at stevemagruder dot com
Reason: useless
----
Here's a simple text file to data array converter:
function file_to_data($sFileIn, $Separator = "|") {
$aFile = array_map("rtrim", file($sFileIn));
$aResult = array();
foreach ($aFile as $FileString) {
$aResult[] = explode($Separator, $FileString);
}
return $arrResult;
}
Here's an example:
File.dat contains...
apple|1|red
orange|2|orange
{eof}
Execute function...
$aData = file_to_data("File.dat");
Results...
$aData[0]
$aData[0][0] = "apple"
$aData[0][1] = "1"
$aData[0][2] = "red"
$aData[1]
$aData[1][0] = "orange"
$aData[1][1] = "2"
$aData[1][2] = "orange"