Parsing Text File
| From: | Jason D. Williard | Date: | Sat, 15 Jun 2002 16:59:03 +0000 |
| Subject: | Parsing Text File | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102355@lists.php.net to get a copy of this message | ||
I am trying to input data from a text file into a MySQL database and would
like to be able to input the data using a single script. What's the easiest
way to parse a line, such as below, and turn it into variables to be placed
in the database. While I can simply place the data in by importing from a
file, it's not quite so easy. I only need to place some of the data in,
plus I would like to split one of the fields. Below is an example of a line
from the file, and then the variables that I need to enter.
Here is an example of a line from the file:
Number,City,State,Country,Provider,Isdn,56K,CreateDate,Active,Timezone,ModDa
te,ModNote
403 -770 -4904 ,CALGARY,AB,CAN,T2,Y,Y,Apr 29 2002
12:00:00:000AM,I,GMT-0700,,
As for variables, I need the following:
Split Number into $AreaCode & $Number > 403 & 770-4904
$City
$State
$Country
Thanks for any help.
Jason D. Williard