0
$book = simplexml_load_string($data);

i have parsed xml string ($data) with simplexml_load_string function
i get below output by printing $book
now i want to assign this data to php variables like $ip_address, $ip_type;$organization etc .. .. so how to assign SimpleXMLElement Object ( [ip_address] => 69.72.129.3 [ip_type] => Mapped [Network] => SimpleXMLElement Object ( [organization] => fortressitx [carrier] => fortressitx [asn] => 25653 [connection_type] => tx [line_speed] => high [ip_routing_type] => fixed [Domain] => SimpleXMLElement Object ( [tld] => net [sld] => cyberleo ) ) [Location] => SimpleXMLElement Object ( [continent] => north america [latitude] => 40.83243 [longitude] => -74.13984 [CountryData] => SimpleXMLElement Object ( [country] => united states [country_code] => us [country_cf] => 99 ) [region] => mid atlantic [StateData] => SimpleXMLElement Object ( [state] => new jersey [state_code] => nj [state_cf] => 95 ) [dma] => 501 [msa] => 35620 [CityData] => SimpleXMLElement Object ( [city] => clifton [postal_code] => 07014 [time_zone] => -5 [area_code] => 973 [city_cf] => 80 ) ) ) info added to database

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by jkon
1

You can use variable variables, of course you have to modify the following example to your needs

$book = simplexml_load_string($data);
		foreach ($book as $key => $value)
		{
		  $$key = (string)$value;
		}
		// example if the book has title 
		echo $title;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.