tommyda Posted November 8, 2008 Share Posted November 8, 2008 I really have no clue whatsoever how to do this. What I need to do is create a function to pull all email addresses from an external xml file then insert them into a database. Example xml file <?xml version="1.0"?> <messenger> <service name=".NET Messenger Service"> <contactlist> <contact type="1">[email protected]</contact> <contact type="1">[email protected]</contact> <contact type="1">[email protected]</contact> <contact type="1">[email protected]</contact> </contactlist> </service> </messenger> If anyone can help me with the basics then that would be greatly appreciated. Thanks Link to comment https://forums.phpfreaks.com/topic/131959-how-do-i-put-this-basic-xml-into-mysql-database/ Share on other sites More sharing options...
htzone Posted November 9, 2008 Share Posted November 9, 2008 You can use this function to turn your XML input into an array: http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html Then cycle through the values with a foreach loop and do what you need to do with them. The output syntax used to access values in the array wasn't totally apparent to me at first - to save you some trouble, this is how you'd get at the email address in the first "contact" entry: $yourArrayName['messenger']['_c']['service']['_c']['contactlist']['_c']['contact']['0']['_v'] You need to change ['0'] to ['1'] to get the next entry, and so on. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/131959-how-do-i-put-this-basic-xml-into-mysql-database/#findComment-685851 Share on other sites More sharing options...
Barand Posted November 9, 2008 Share Posted November 9, 2008 $xml = simplexml_load_file('my.xml'); foreach ($xml->xpath('//contact') as $con) { echo $con,'<br/>'; } Link to comment https://forums.phpfreaks.com/topic/131959-how-do-i-put-this-basic-xml-into-mysql-database/#findComment-685892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.