note 62273 added to function.file

From: Date: Thu, 23 Feb 2006 21:00:35 +0000
Subject: note 62273 added to function.file
Groups: php.notes 
Request: Send a blank email to php-notes+get-104325@lists.php.net to get a copy of this message
Just a quickie note- I was trying to find a way to get the contents of a .CSV file into a database and had to work at it quite a bit. the file was set up as a multi-dimensional array eg: item1 name,item1 description,item1 attribute,etc item2 name,item2 description,item2 attribute,etc item3 name,item3 description,item3 attribute,etc I wanted to take the elements of each line and import them to the proper field of a certain table in an MS SQL Server database. the following code worked: //get filecontents into array $rsFileContents = file("C:/webserver/webpages/folder/".$BulkImportFile); //loop through array elements and explode each element into a new array $i=count($rsFileContents); //this gets the number of lines(elements) that need to be exploded $x=0; While($x<$i){ $newContents = explode(',', $rsFileContents[$x]); //modify any elements that need to be modified and insert them into the proper db field $weight=rtrim($newContents[10]); $rsInputFileContents = $db->Execute("INSERT INTO tablename (Item_Name,Item_Desc,Item_attribute) Values ('$newContents[0]','$newContents[1]','$newContents[2]',etc))"); $x++; } Hope this helps someone.......... ---- Server IP: 64.71.164.2 Probable Submitter: 209.165.189.18 (proxied: 1.0 BP1ANCPX001) ---- Manual Page -- http://www.php.net/manual/en/function.file.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62273 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62273&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62273&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104325) next »