sineverba
sineverba

Reputation: 5172

From SimpleXML to variable

I'm reading an XML with SimpleXML. A node is made in this mode:

$docType    = $doc->DocumentType;

If i do

print_r($docType);

I'm getting:

SimpleXMLElement Object ( [0] => B )

And this is right. Now, i need to "simply" put the "B" into a variable, to obtain this goal:

$daneadoc['B'] = 'Scontrino / Vendita al banco';
$daneadoc['I'] = 'Fattura';

(I have an array for several value for "daneadoc").

Obviously, if I put

echo $daneadoc[$docType];

It's Illegal offset type

But if i write

 $documento = $docType[0];
 echo $daneadoc[$documento];

My server says same (illegal type). Same if I write

 echo $daneadoc[$docType[0]];

My question is... How i can convert obkect in a single variable to put in the array $daneadoc?

Thank you very much!

Upvotes: 0

Views: 58

Answers (2)

Tash Pemhiwa
Tash Pemhiwa

Reputation: 7685

I am not sure if I understood your question, but try:

$docTypeString = (string) $docType;
$daneadoc[$docTypeString] = 'Scontrino / Vendita al banco';

Upvotes: 1

JoDev
JoDev

Reputation: 6873

You are searching for the getName() method? You want to retrieve the tag name?

Use it like this : $docType->getName()

Upvotes: 0

Related Questions