Member Avatar for nova37
$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

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.