您好,欢迎访问一九零五行业门户网

php 生成xml代码_PHP教程

php 生成xml代码class xmlparser {
 function getchildren($vals, &$i) {
  $children = array();
  if(isset($vals[$i]['value'])) {
   $children['value'] = $vals[$i]['value'];
  }
  while(++$i    switch($vals[$i]['type']) {
   case 'cdata':
    if(isset($children['value'])) {
     $children['value'] .= $vals[$i]['value'];
    } else {
     $children['value'] = $vals[$i]['value'];
    }
    break;
   case 'complete':
    if(isset($vals[$i]['attributes'])) {
     $children[$vals[$i]['tag']][]['attributes'] = $vals[$i]['attributes'];
     $index = count($children[$vals[$i]['tag']]) - 1;
     if(isset($vals[$i]['value'])) {
      $children[$vals[$i]['tag']][$index]['value'] = $vals[$i]['value'];
     } else {
      $children[$vals[$i]['tag']][$index]['value'] = '';
     }
    } else {
     if(isset($vals[$i]['value'])) {
      $children[$vals[$i]['tag']][]['value'] = $vals[$i]['value'];
     } else {
      $children[$vals[$i]['tag']][]['value'] = '';
     }
    }
    break;
   case 'open':
    if(isset($vals[$i]['attributes'])) {
     $children[$vals[$i]['tag']][]['attributes'] = $vals[$i]['attributes'];
     $index = count($children[$vals[$i]['tag']]) - 1;
     $children[$vals[$i]['tag']][$index] = array_merge($children[$vals[$i]['tag']][$index], $this->getchildren($vals, $i));
    } else {
     $children[$vals[$i]['tag']][] = $this->getchildren($vals, $i);
    }
    break;
   case 'close':
    return $children;
   }
  }
 }
 function getxmltree($data) {
  $parser = xml_parser_create('utf-8');
  xml_parser_set_option($parser, xml_option_skip_white, 0);
  xml_parser_set_option($parser, xml_option_case_folding, 0);
  xml_parse_into_struct($parser, $data, $vals, $index);
  xml_parser_free($parser);
  $tree = array();
  $i = 0;
  if(isset($vals[$i]['attributes'])) {
   $tree[$vals[$i]['tag']][]['attributes'] = $vals[$i]['attributes'];
   $index = count($tree[$vals[$i]['tag']]) - 1;
   $tree[$vals[$i]['tag']][$index] =  array_merge($tree[$vals[$i]['tag']][$index], $this->getchildren($vals, $i));
  } else {
   $tree[$vals[$i]['tag']][] = $this->getchildren($vals, $i);
  }
  return $tree;
 }
}
http://www.bkjia.com/phpjc/632011.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/632011.htmltecharticlephp 生成xml代码class xmlparser { function getchildren($vals, $i) { $children = array(); if(isset($vals[$i]['value'])) { $children['value'] = $vals[$i]['value']; } while(++$i co...
其它类似信息

推荐信息