I've got up to
$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");
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
Fatal error: Cannot use object of type DOMElement as array in test.php on line 6
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!