Created
December 14, 2019 17:12
-
-
Save pc-magas/760c8dd88902e5fb1e1d2d276fcb9bed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
// Input CSV | |
$csv_file="contacts (3).csv"; | |
// Output file | |
$ldap="contacts.ldif"; | |
/** | |
* ###################### Do not edit ellow this line ################## | |
*/ | |
$ldapHandler=fopen($ldap,"w"); | |
$csv_file_handler=fopen($csv_file,"r"); | |
$recordHeader="dn: uid=card-id-5db070a957116,ou=Users,dc=mydomain,dc=gr".PHP_EOL."objectclass: inetOrgPerson".PHP_EOL; | |
$firstLineSkip=true; | |
if (($csv_file_handler=fopen($csv_file,"r")) !== FALSE) { | |
while (($data = fgetcsv($csv_file_handler, 1000, ",")) !== FALSE) { | |
if($firstLineSkip) { | |
$firstLineSkip=false; | |
continue; | |
} | |
$email=trim($data[30]); | |
$cn=trim($data[0]); | |
$sn=trim($data[3]); | |
$givenName=$data[1]; | |
$mobile=str_replace(' ','',$data[32]); | |
$mobile=str_replace('+','00',$mobile); | |
$phone=str_replace(' ','',$data[34]); | |
$phone=str_replace('+','00',$phone); | |
$record=$recordHeader; | |
$record.='cn:'.$cn.PHP_EOL; | |
$record.='sn:'.$sn.PHP_EOL; | |
$record.='givenName:'.$givenName.PHP_EOL; | |
$record.='email:'.$email.PHP_EOL; | |
$record.='mobile:'.$mobile.PHP_EOL; | |
$record.='telephoneNumber:'.$phone.PHP_EOL; | |
$record.='uid: card-id-5db070a957116'; | |
fwrite($ldapHandler,$record.PHP_EOL.PHP_EOL); | |
} | |
} | |
fclose($ldapHandler); | |
fclose($csv_file_handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment