GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP and xml help! (https://gfy.com/showthread.php?t=1011571)

CS-Jay 02-23-2011 08:34 AM

PHP and xml help!
 
I'm a bit stuck and hope someone can lend a hand. I cannot get the value of, Choice, using simplexml.

Here's the xml:

PHP Code:

<Choice ID="1000">
<
Select NAME="BOB/>
Monday
</Choice>
<Choice ID="
1001">
<Select NAME="
Mary/>
Tuesday
</Choice

I am looping through, trying to get the value of Choice, but I get the array of Select. I would like just get the days.

PHP Code:

$arr = array();
foreach (
$Choice AS $choice){
$arr[] = $choice;
}
print_r($arr); 

Any ideas?

potter 02-23-2011 09:00 AM

You're going to want an XML parser to parse the XML into an array.

http://php.net/manual/en/function.xml-parse.php

http://php.net/manual/en/function.xm...nto-struct.php

CS-Jay 02-23-2011 09:07 AM

Quote:

Originally Posted by potter (Post 17935516)
You're going to want an XML parser to parse the XML into an array.

http://php.net/manual/en/function.xml-parse.php

http://php.net/manual/en/function.xm...nto-struct.php

I guess I should stop resisting using anything else than simplexml.

HarryMuff 02-23-2011 09:33 AM

Use DOM? Don't think you can get the textNode children using simplexml.

Code:

$xml =
'<derp>
    <Choice ID="1000">
        <Select NAME="BOB" />
        Monday
    </Choice>
    <Choice ID="1001">
        <Select NAME="Mary" />
        Tuesday
    </Choice>
</derp>';
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXML($xml);
foreach($dom->getElementsByTagName('Choice') as $choice)
{
    $arr[] = $choice->textContent;
}
print_r($arr);


CS-Jay 02-23-2011 10:06 AM

Quote:

Originally Posted by HarryMuff (Post 17935584)
Use DOM? Don't think you can get the textNode children using simplexml.

Code:

$xml =
'<derp>
    <Choice ID="1000">
        <Select NAME="BOB" />
        Monday
    </Choice>
    <Choice ID="1001">
        <Select NAME="Mary" />
        Tuesday
    </Choice>
</derp>';
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXML($xml);
foreach($dom->getElementsByTagName('Choice') as $choice)
{
    $arr[] = $choice->textContent;
}
print_r($arr);


Off to give DOM a try


All times are GMT -7. The time now is 04:18 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc