Jump to content

SimpleXML Question


N-Bomb(Nerd)

Recommended Posts

Hi, I'm new to SimpleXML and I'm trying to learn.

 

I'm trying to figure out how to delete a child ( and all sub-children ), however I'm not doing very good.

 

Was hoping someone could explain to me what I'm doing wrong..

 

test.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<man>
<phone company="verizon">
	<r>empty</r>
</phone>

<phone company="att">
	<r>empty</r>
</phone>

<phone>
	<r>empty</r>
</phone>
</man>

 

test.php

$phones = array("verizon");
$xml = simplexml_load_file('test.xml');

foreach ($xml as $phone) {
if (in_array((string) $phone['company'], $phones)) {
	unset($xml->$phone);
}
}

print_r($xml);

 

As you can see the phone with the company = "verizon" is still in the xml.. how do I get it to remove?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/185511-simplexml-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.