jamiesalter Posted November 2, 2006 Share Posted November 2, 2006 Hello all,I'm having problems using simpleXML in PHP. I am trying to assign an elements data to a variable. Normally the following would work:[color=blue]$xml = simplexml_load_file($file);foreach ($xml->item as $item) {$manu = trim(addslashes($item->manufacturer));...}[/color]However my problem occurs when the elements name contains a colon. For example, if instead of [color=blue]$item->manufacturer[/color] it was [color=blue]$item->g:brand[/color] php produces an error because of the colon producing an invalid variable name. Is it possible to escape the colon somehow, whilst still instructing simpleXML to get the data of g:brand?Any comments or help would be gratefully appreciated,Jamie Salterjbhhockey.co.uk Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2006 Share Posted November 2, 2006 The only suggestion I can think of would be to first read the file contents and replace any colons with either a replacement character or with nothing. Then do your XML parsing. Quote Link to comment Share on other sites More sharing options...
buttercupgreen Posted November 5, 2006 Share Posted November 5, 2006 Here, let me show you how I use Simple_XML functions to read and write XML files.[url=http://www.dev-tips.org/index.php?title=xml_sample]http://www.dev-tips.org/index.php?title=xml_sample[/url] 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.