homepage Welcome to WebmasterWorld Guest from 54.196.201.253
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Need to populate array (with keys) from for each loop
Populate array from xml file
dpinion




msg:4391780
 8:33 pm on Nov 28, 2011 (gmt 0)

Hey All,
This should be pretty easy, but I am just a bit new to this part of the game.. :) I have a simple xml file that I am loading and using to load different page content (I get the XML file from others in our group pre-filled). Anyway, I wrote the following:


<?php
$xml = simplexml_load_file("info.xml");
$xmlarray = array();
foreach($xml->children() as $child)
{
$xmlarray[] = $child;
}
?>



This works fine, but now it has come up that I need to check the field names, as we can have slight variations due to # of bullets needed/etc...

I assume the easiest way to handle this would be to also assign the xml field names as keys into the array and then check against that in php. This is where I am stuck, trying to grab those field names. Ultimately the array values would be something like:

$xmlarray('field1' => 'value')

am I on the right track here? Any help is appreciated.

 

httpwebwitch




msg:4391794
 9:05 pm on Nov 28, 2011 (gmt 0)

not sure what you mean by "field names" in XML. Are these child nodes of each $child? Or are they the $child nodes themselves?

a sample of the XML you're parsing would help (just a small fragment would suffice)

dpinion




msg:4391808
 9:29 pm on Nov 28, 2011 (gmt 0)

Yes sorry, got the terminology wrong. So something like so...

<pagedata>
<field1>This is the data for field 1</field1>
<field2>This is the data for field 2</field2>
</pagedata>

So essentially I would want an array that would contain "field1" as the key as well as the data the node contains. Hope that makes more sense.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved