Jump to content

[SOLVED] Converting XML Object to String


Psycho

Recommended Posts

I am converting an XML file into an object via

 

$xml_data = simplexml_load_file('xmldata\test.xml');

 

However I run into a problem if I try to use a value within that XML object as a string:

 

<?php

$id = $xml_data->id;
$array[$id]['keyname'] = $xml_data->keyname;

?>

 

Results in the error Warning: "Warning Illegal offset type in C:\xampp\htdocs_dvd\xml.php on line 120"

 

I can avoid the error by enclosing the value in quotes when assigning to a variable such as this:

 

<?php

$id = "$xml_data->id";
$array[$id]['keyname'] = $xml_data->keyname;

?>

 

Is this the best approach?

Link to comment
https://forums.phpfreaks.com/topic/73840-solved-converting-xml-object-to-string/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.