Importing contacts from outlook csv in php
Hi can some body help me on how can i import contacts fro开发者_如何学Cm a outlook file. I assume it's a form of csv file
Something like below should work for a standard CSV(I am not sure if outlook makes any non standard changes to the format
$csvLines = file(/path/to/file.csv);
$values = array();
foreach($csvLines as $line)
{
$fields = explode(',', $line);
$fieldsTrimmed = array();
foreach($fields as $field)
{
$field = trim($field)
$fieldsTrimmed[] = trim($field, '"');
}
$values[] = $fieldsTrimmed;
}
The array values should have all the data with $values[0] showing the field names.
PHP can directly read CSV files.
I found out that it was allowed export as tab seperated values. Which is a txt file. I used file-get-contents with str-getcsv to parse it into a array.
str-getcsv(file-get-contents($file), "\t")
if you wish to use csv file the use the following
str-getcsv(file-get-contents($file), ",")
精彩评论