function parseContacts($filename) { $contactsArray = array(); // todo - read file and parse contacts $handle = fopen($filename, 'r'); $contentString = trim(fread($handle, filesize($filename))); $arrayOfStrings = explode(PHP_EOL, $contentString); foreach ($arrayOfStrings as $index => $contact) { $innerArray = explode('|', $contact); unset($arrayOfStrings[$index]); $contactsArray[$index]['name'] = $innerArray[0]; $contactsArray[$index]['number'] = numberSplit($innerArray[1]); } fclose($handle); return $contactsArray; }
function parseContacts($filename) { $contacts = array(); $handle = fopen($filename, 'r'); $contents = fread($handle, filesize($filename)); $contents = trim($contents); $contacts = explode("\n", $contents); fclose($handle); foreach ($contacts as $index => $contact) { $contact = explode('|', $contact); unset($contacts[$index]); // $number = substr_replace($number, '-', 3, 0); // $number = substr_replace($number, '-', 7, 0); // $contacts[$index]['name'] = $contact[0]; // $contacts[$index]['number'] = numberSplit($contact[1]); $contacts[$index] = ['name' => $contact[0], 'number' => numberSplit($contact[1])]; } return $contacts; }