I am trying to load data from a pipe seperated text file into PHP script to ultimately load it into SQL Server DB.
I am trying to load the contents into an array, but that keeps on failing. Pls. suggest a solution to this.
Thanks.
Extracting data from text file
Moderator: General Moderators
Code: Select all
$handle = fopen(fileNameCreator("orders"), "rb");
$contents = stream_get_contents($handle);
fclose($handle);
$dataArray = array();
$dataArray = explode(",", trim($contents));-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
If it's pipe seperated, you need to use:
Code: Select all
$dataArray = explode("|", trim($contents));-
blackbeard
- Forum Contributor
- Posts: 123
- Joined: Thu Aug 03, 2006 6:20 pm
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Might try
Code: Select all
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$dataArray = explode(",",$contents);
echo "<PRE>";
print_r($dataArray);
echo "</pre>";