Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一起<;说明>;元素if<;特征类型>;元素在XML PHP解析中是相同的_Php_Xml_Xml Parsing - Fatal编程技术网

一起<;说明>;元素if<;特征类型>;元素在XML PHP解析中是相同的

一起<;说明>;元素if<;特征类型>;元素在XML PHP解析中是相同的,php,xml,xml-parsing,Php,Xml,Xml Parsing,xml.php 需要这样的输出吗 SimpleXMLElement Object ( [feature_type] => Copier Features [description] => Copier description1 Copier description2 ) SimpleXMLElement Object ( [feature_

xml.php

需要这样的输出吗

      SimpleXMLElement Object
    (
        [feature_type] => Copier Features
        [description] => Copier description1
                         Copier description2  
    )
    SimpleXMLElement Object
    (
        [feature_type] => Facsimile Features
        [description] => Facsimile description1
                         Facsimile description2
    )
这样做:

$xml = simplexml_load_string($xmlstr,'SimpleXMLElement', LIBXML_NOCDATA);

$x = count($xml->product_features->feature_item)-1;
$ft = ''; $d = '';

for ($x ; $x >= 0 ; $x--) {

    if ($ft == (string)$xml->product_features->feature_item[$x]->feature_type) {

        $xml->product_features->feature_item[$x]->description = $xml->product_features->feature_item[$x]->description . " $d";

    } else {

        $ft = (string)$xml->product_features->feature_item[$x]->feature_type;
        $d = (string)$xml->product_features->feature_item[$x]->description;
        unset($xml->product_features->feature_item[$x]);
    }   
}

echo "<pre>";
var_dump($xml);
echo "</pre>";
$xml=simplexml\u load\u字符串($xmlstr,'simplexmlement',LIBXML\u NOCDATA);
$x=计数($xml->product\u features->feature\u item)-1;
$ft=''$d='';
对于($x;$x>=0;$x--){
如果($ft==(字符串)$xml->product\u features->feature\u item[$x]->feature\u type){
$xml->product\u features->feature\u item[$x]->description=$xml->product\u features->feature\u item[$x]->description.“$d”;
}否则{
$ft=(字符串)$xml->product\u features->feature\u item[$x]->feature\u type;
$d=(字符串)$xml->product\u features->feature\u item[$x]->description;
取消设置($xml->product\u features->feature\u item[$x]);
}   
}
回声“;
    $xml = simplexml_load_file('xml.php','SimpleXMLElement', LIBXML_NOCDATA); 
    foreach($xml as $rows)
    {    
        foreach($rows as $row){ 
                       echo "<pre>";
                      print_r($row);
                       echo "</pre>";
        }
    }
var_dump($xml); 回声“;
    $xml = simplexml_load_file('xml.php','SimpleXMLElement', LIBXML_NOCDATA); 
    foreach($xml as $rows)
    {    
        foreach($rows as $row){ 
                       echo "<pre>";
                      print_r($row);
                       echo "</pre>";
        }
    }
在描述之间添加空格。
见现场演示:

$xml = simplexml_load_string($xmlstr,'SimpleXMLElement', LIBXML_NOCDATA);

$x = count($xml->product_features->feature_item)-1;
$ft = ''; $d = '';

for ($x ; $x >= 0 ; $x--) {

    if ($ft == (string)$xml->product_features->feature_item[$x]->feature_type) {

        $xml->product_features->feature_item[$x]->description = $xml->product_features->feature_item[$x]->description . " $d";

    } else {

        $ft = (string)$xml->product_features->feature_item[$x]->feature_type;
        $d = (string)$xml->product_features->feature_item[$x]->description;
        unset($xml->product_features->feature_item[$x]);
    }   
}

echo "<pre>";
var_dump($xml);
echo "</pre>";