尝试在PHP中读取XML文件变量

尝试在PHP中读取XML文件变量,php,parsing,xml-parsing,Php,Parsing,Xml Parsing,我有如下计划的xml列表: <plans> <plan> <name>LITE</name> <description>description</description> <rate>$9/Month</rate> <price>5</price> <period>1</per

我有如下计划的xml列表:

<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>
给, 清淡的 专业的

那么你就可以做条件检查了

    //$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);
        }
    }
foreach ($plans_xml->plan as $item){
    var_dump( $item->name );
}