在php中从outlook csv导入联系人

问题描述:

Hi can some body help me on how can i import contacts from a outlook file. I assume it's a form of csv file

您可以帮助我如何从Outlook文件导入联系人。 我假设它是csv文件的一种形式 p> div>

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), ",")

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.