Help a PHP newbie with strings/arrays/xml?
Posted: Thu Jul 15, 2004 6:57 pm
I am very new to PHP, although not so new to programming and would appreciate a little help on the following:
My PHP app (my first) reads an XML file, parses it and feeds it into an array...that all works fine.
My problem is trivial and can be sorted with extra coding - I just wondered if anyone knew of an elegant solution.
Here goes...
For XML string fields which may contain single or multiple entries, PHP treats them as either an array of strings or a string. Outputting them using count(array) results in either the correct results for arrays (array[index]) or the incorrect result for strings i.e. if count(array) = 1 then echo array[1] echoes the first character of the string.
I could apply extra coding simply to test the array count and provide different output routines for each scenario, but this seems a little dumb and I am sure there must be a better way...
My PHP app (my first) reads an XML file, parses it and feeds it into an array...that all works fine.
My problem is trivial and can be sorted with extra coding - I just wondered if anyone knew of an elegant solution.
Here goes...
For XML string fields which may contain single or multiple entries, PHP treats them as either an array of strings or a string. Outputting them using count(array) results in either the correct results for arrays (array[index]) or the incorrect result for strings i.e. if count(array) = 1 then echo array[1] echoes the first character of the string.
I could apply extra coding simply to test the array count and provide different output routines for each scenario, but this seems a little dumb and I am sure there must be a better way...