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 Link to comment https://forums.phpfreaks.com/topic/25966-simplexml-help/ 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. Link to comment https://forums.phpfreaks.com/topic/25966-simplexml-help/#findComment-118774 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] Link to comment https://forums.phpfreaks.com/topic/25966-simplexml-help/#findComment-119888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.