You are here:  » Extracting values of array records


Extracting values of array records

Submitted by Werner Berghofer on Wed, 2008-09-17 12:58 in

How is it possible to extract certain values found in these example records:

Array ( [DICT] => [KEY] => channels [INTEGER] => 2 [KEY@1] => copyPermitted [FALSE] => [KEY@2] => dataTrack [FALSE@1] => [KEY@3] => firstSector [INTEGER@1] => 61482 [KEY@4] => lastSector [INTEGER@2] => 96528 [KEY@5] => number [INTEGER@3] => 3 [KEY@6] => preEmphasis [FALSE@2] => [KEY@7] => title [STRING] => Another place )

Array ( [DICT] => [KEY] => channels [INTEGER] => 2 [KEY@1] => copyPermitted [FALSE] => [KEY@2] => dataTrack [FALSE@1] => [KEY@3] => firstSector [INTEGER@1] => 61482 [KEY@4] => lastSector [INTEGER@2] => 96528 [KEY@5] => number [INTEGER@3] => 3 [KEY@6] => preEmphasis [FALSE@2] => [KEY@8] => title [STRING@1] => Another place )

I included a second example record to show that sometimes the title can be the value of [STRING], [STRING@1] and so on. The record is checked by the PHP function

if (in_array ('title', $record))

title is present in each record, but the location within the array changes depending on the structure of the XML file which is being parsed by MagicParser.

Many thanks in advance – and please excuse my bad English, it’s not my native language,

Werner.

Submitted by support on Wed, 2008-09-17 13:05

Hello Werner,

This looks like very tricky XML, because they seem to be encoding values as tag names!

Can you send me an example of the XML so I can try it out and write some code to do this for you?

Please reply to your registration code email to get me, then I will have a look at the XML...

Thanks,
David.

Submitted by Werner Berghofer on Wed, 2008-09-17 13:38

David,

This looks like very tricky XML, because they seem to be encoding values as tag names!

you’re right, this is a very odd XML scheme. In fact, unfortunately it’s exactly the same scheme Apple computer uses for its own plist-Files, omnipresent in any version of Mac OS X.

I’ll send you an example XML file via e-mail within the next few minutes.

However, maybe the question is not that difficult at all: I already know how to extract the specific location of the key:

$keys = array_search ('title', $record);

But how do I access its value?

Many thanks for your quick reply,

Werner.