jdoe Posted May 13, 2006 Share Posted May 13, 2006 I'm working on a script to adapt the results from an existing script, which are arrays of text strings, into XML. After having some frustrating trouble with Active-Link's XML library, I've taken a break and am working with straight PHP using DOM.I've got up to[code]$dom = new DomDocument('1.0', 'utf-8');$dom->formatOutput = true; $item = $dom->createElement("item");$title = $dom->createElement("title");$titletext = $dom->createTextNode($array['title']);$title->appendChild($titletext);$item->appendChild($title);$dom->appendChild($item);$dom->save("test.xml");[/code]With the array in the sixth line above, and the whole thing in a foreach. My intent is for the foreach to apply this to each value in the array in turn.When I run the script, however, I get the error [code]Fatal error: Cannot use object of type DOMElement as array in test.php on line 6[/code]I at first thought explode might work, but the array doesn't appear to have a delimiter (it does operate normally with "echo," so I feel it's well formed, however strangely), that is, when one calls "echo $array;" or "print_r($array);", the results are valuevaluevalue, though "echo '$array<br />';", as I'd been using it before and it's meant to be used, returns the values line broken.What's the correct way to solve this? I know this is a strange way to present the problem, but I'm hoping what I'm doing wrong is simple enough that someone'll understand without my having to try and replicate it in example code. Is there some function of DOM I haven't yet found that'll accept and pass the values of an array in turn like this?Any help's very much appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.