On 11/10/2011 05:45 PM, Bastien Koert wrote:
Can someone point me in the correct direction? It may be that I need
to manually create the key names as an array first, which I was hoping
to avoid since the file format coming from the client is still in some
flux.
<?php

//$data = file("inline_Nov_8_2011.txt");
$data = array('Legal Last Name|Legal Middle Initial|Legal First Name|Maiden/Other Name|Social Insurance No.|Date of Birth|Gender',
        'Andros||Marisa||123456789|2/1/1988|Female');

$json = '';
if(count($data)==2){

    $keys     = explode("|", $data[0]);
    $fields = explode("|", $data[1]);

    $combine = array_combine($keys, $fields);

    $json = json_encode($combine);
}

echo $json;
?>

That's the code I've just used.

And it gave me perfect output:
{"Legal Last Name":"Andros","Legal Middle Initial":"","Legal First Name":"Marisa","Maiden\/Other Name":"","Social Insurance No.":"123456789","Date of Birth":"2\/1\/1988","Gender":"Female"}

What version of the PHP do you use?

--
Best regards,
DiRaven

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to