php - converting ini to array in needed format using parse_ini_file - not getting desired output -
i have data pulled in query includes presenter information. formatted this:
[doe, john undefined] middle_name = e. department = psychology institution = special state university city = anywhere state = texas country = usa office_phone = 123-456-7891 cell_phone = 123-789-4578 email_address = john_doe@there.edu website = www.johndoe.edu [doe, jane undefined] middle_name = department = political science institution = special university city = anywhere state = indiana country = usa office_phone = 123-456-7891 cell_phone = 568-456-4589 email_address = janedoe@here.edu website =
i need display this:
john doe, psychology, special state university
jane doe, political science, special university (each presenter on separate line)
i have tried this:
$cleanpresenters = parse_ini_file($data['presenters'])
;
and produces in error log:
parse_ini_file([doe, john undefined]\nmiddle_name = e.\ndepartment = psychology\ninstitution = special state university\ncity = anywhere\nstate = texas\ncountry = usa\noffice_phone = 123-456-7891\ncell_phone = \nemail_address = john_doe@there.edu\nwebsite = \n\n): failed open stream: file name long in -file path name.proposalpdf.php on line 21, referer: filepath name
i pretty php newbie , don't know next fix error , want. there may 1 presenter or there may several solution needs loop until runs through presenters. appreciated.
update: changing parse_ini_string , echo array, this:
array ( [middle_name] => [department] => political science [institution] => special university [city] => anywhere [state] => indiana [country] => usa [office_phone] => 123-456-7891 [cell_phone] => 568-456-4589 [email_address] => janedoe@here.edu [website] => )
so far, good. how turn format desire?
i figured out based on research , example else had written.
//convert presenter data array string $cleanpresenters = parse_ini_string($data['presenters'],true); foreach ($cleanpresenters $name=>$val1) { $name = trim($name); $presenters[] = $name; $convertedpresenters .= "$name, {$val1['department']}, {$val1['institution']}\n"; };
the above did trick. each presenter prints name, department, institution on single line. tips , points in right direction.
Comments
Post a Comment