2013-03-30 30 views
0

我的计划是这样的XML列表:尝试读取XML文件中的变量在PHP

<plans> 
    <plan> 
     <name>LITE</name> 
     <description>description</description> 
     <rate>$9/Month</rate> 
     <price>5</price> 
     <period>1</period> 
     <units>MONTH</units> 
     <recurring>1</recurring> 
     <acl>2</acl> 
    </plan> 
    <plan> 
     <name>PRO</name> 
     <description>description</description> 
     <rate>$10/Year</rate> 
     <price>5</price> 
     <period>1</period> 
     <units>YEAR</units> 
     <recurring>0</recurring> 
     <acl>3</acl> 
    </plan> 
</plans> 

但我不知道如何解析出“期”和“单位” PARAMS。我正在尝试这样做,但我认为出现了问题 - 就像我没有正确处理DOM。

//$plan is already set above. 
    $plans_xml = simplexml_load_file("../plans.xml"); 
    foreach ($plans_xml->plan->name as $item){ 
     //if the plan in the xml matches the plan the user signed up for 
     if ($item == $plan){ 
     //set interval by concatenating period and units 
     $interval = ($plans_xml->plan->period . $plans_xml->plan->units); 
     } 
    } 

回答

0
foreach ($plans_xml->plan as $item){ 
    var_dump($item->name); 
} 

给人, LITE PRO

,那么你可以做你的条件检查