国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院

首頁 > 編程 > PHP > 正文

PHP實現(xiàn)XML與數(shù)據(jù)格式進行轉(zhuǎn)換類實例

2020-03-22 20:08:05
字體:
供稿:網(wǎng)友
本文實例講述了PHP實現(xiàn)XML與數(shù)據(jù)格式進行轉(zhuǎn)換類。分享給大家供大家參考。具體如下: * xml2array() will convert the given XML text to an array in the XML structure. * Link: http://www.bin-co.com/php/scripts/xml2array/ * Arguments : $contents - The XML text * $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag html' target='_blank'>values - this results in a different array structure in the return value. * $priority - Can be 'tag' or 'attribute'. This will change the way the resulting array sturcture. For 'tag', the tags are given more importance. * Return: The parsed XML in an array form. Use print_r() to see the resulting array structure. * Examples: $array = xml2array(file_get_contents('feed.xml')); * $array = xml2array(file_get_contents('feed.xml', 1, 'attribute'));function xml2array($contents, $get_attributes = 1, $priority = 'tag') { if (!$contents) return array(); if (!function_exists('xml_parser_create')) { // print "'xml_parser_create()' function not found!"; return array(); // Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); // http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if (!$xml_values) return; //Hmm... // Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference // Go through the tags. $repeated_tag_index = array(); //Multiple tags with same name will be turned into an array foreach($xml_values as $data) { unset($attributes, $value); //Remove existing values, or there will be trouble // This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data); //We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if (isset($value)) { if ($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode // Set the attributes too. if (isset($attributes) and $get_attributes) { foreach($attributes as $attr = $val) { if ($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' // See tag status and do the needed. if ($type == "open") { // The starting of the tag ' tag ' $parent[$level-1] = &$current; if (!is_array($current) or (!in_array($tag, array_keys($current)))) { // Insert New tag $current[$tag] = $result; if ($attributes_data) $current[$tag . '_attr'] = $attributes_data; $repeated_tag_index[$tag . '_' . $level] = 1; $current = &$current[$tag]; } else { // There was another element with the same tag name if (isset($current[$tag][0])) { // If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; $repeated_tag_index[$tag . '_' . $level]++; } else { // This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag], $result); //This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag . '_' . $level] = 2; if (isset($current[$tag . '_attr'])) { // The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset($current[$tag . '_attr']); $last_item_index = $repeated_tag_index[$tag . '_' . $level]-1; $current = &$current[$tag][$last_item_index]; } elseif ($type == "complete") { // Tags that ends in 1 line ' tag / ' // See if the key is already taken. if (!isset($current[$tag])) { // New Key $current[$tag] = $result; $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $attributes_data) $current[$tag . '_attr'] = $attributes_data; } else { // If taken, put all things inside a list(array) if (isset($current[$tag][0]) and is_array($current[$tag])) { // If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; if ($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; $repeated_tag_index[$tag . '_' . $level]++; } else { // If it is not an array... $current[$tag] = array($current[$tag], $result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $get_attributes) { if (isset($current[$tag . '_attr'])) { // The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset($current[$tag . '_attr']); if ($attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken } elseif ($type == 'close') { // End of tag ' /tag ' $current = &$parent[$level-1]; return($xml_array);// Array to XMLclass array2xml { public $output = " xml version=/"1.0/" encoding=/"utf-8/" public $sub_item = array(); public function __construct($array) { $sub_item = array(); $this- output .= $this- xmlmake($array); public function xmlmake($array, $fk = '') { $xml = ''; global $sub_item; foreach ($array as $key = $value) { if (is_array($value)) { if (is_numeric($key)) { $this- sub_item=array_merge($this- sub_item,array($fk)); $xml .= " {$fk} " . $this- xmlmake($value, $key) . " /{$fk} } else { $xml .= " {$key} " . $this- xmlmake($value, $key) . " /{$key} } else { $xml .= " {$key} {$value} /{$key} return $xml; public function output(){ foreach($this- sub_item as $t){ $this- output = str_replace(" {$t} {$t} "," {$t} ",$this- output); $this- output = str_replace(" /{$t} /{$t} "," /{$t} ",$this- output); return $this- output;}希望本文所述對大家的php程序設(shè)計有所幫助。PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
国产激情自拍_国产9色视频_丁香花在线电影小说观看 _久久久久国产精品嫩草影院
国内a∨免费播放| 国产精品视频一区二区三区麻豆| 精品入口蜜桃| 精品日韩av| 国产极品视频| 亚洲图区综合| 在线91av| 亚洲综合天堂网| 国产卡二和卡三的视频| 精品视频二区| 高清av中文在线字幕观看1| 国产在线www| 国产青青视频| www.av在线| 国产一级粉嫩xxxx| 精品久久久久一区二区三区| www.色五月| 国产午夜在线视频| 在线免费看av| 国产乱人视频免费播放| 亚洲夜夜综合| 国产精品人人爱一区二区白浆| 亚洲精品影视在线| 国产午夜三区视频在线| 免费女人毛片视频| 99色在线观看| 国产图片综合| 国产资源在线看| av在线第一页| 樱花草在线观看www| 中文字幕在线观看日本| 热99re久久精品精品免费| 国产图片综合| 国产免费专区| 国产专区在线播放| 免费看的毛片| 毛片在线视频| 成人av小说网| 久热av在线| 麻豆精品永久免费视频| www狠狠操| аⅴ成人天堂中文在线| 不卡av免费观看| 日本欧美在线视频免费观看| 亚洲久草视频| 日韩国产成人| 青青草视频在线免费观看| 在线中文字幕视频| 国产精品久久久久白浆| 国产日产一区二区三区| 最新天堂资源在线| 国产网红在线| 国产黄在线观看| 国产www视频在线观看| 国产精品黄页网站在线播放免费 | 在线观看精品视频一区二区三区| 国产黄色免费看| 中文资源在线官网| 欧美日韩**字幕一区| 国产又色又爽又黄刺激在线视频| 国产永久免费高清在线观看视频| 亚洲精品一线| 国产在线超碰| 精品国产二区三区| 国产在线小视频| 国产色在线观看| av中文网站| 国产污污在线观看| 男人天堂v视频| 精品无人乱码| 九九在线视频| 精品视频二区| 五月婷婷在线观看| h网址在线观看| 国产成a人亚洲精v品| 交视频在线观看国产| 国产羞羞视频在线播放| 亚洲国产aⅴ精品| 中文字幕国产欧美| www网站在线观看| 精品国产高清a毛片无毒不卡 | 天天操天天曰| 伊人影院在线播放| 国产精品入口麻豆电影| 美女av在线播放| 99热国产在线| 国产一区二区三区福利| h网址在线观看| 在线中文字幕资源| 国产黄色一级电影| 国产一级视频| 中文字幕一区免费| 国产亚洲精品午夜高清影院| 国产乱子视频| 日本中文字幕在线看| 超碰在线人人| 久草福利资源在线视频| 老师我好爽再深一点的视频| www.xxx黄| 麻豆福利在线观看| 九九久久久2| 毛片网站在线观看| 免费的黄网站在线观看| 欧美日韩在线视频免费观看| 日日夜夜中文字幕| 欧美精品久久久久久久小说| 青青草视频在线免费观看| 男女午夜视频在线观看| 国产免费av高清在线| 天天av综合网| 中文字幕毛片| 国产高清免费在线播放| 国产精品99999| 在线国产小视频| www.操操操| 国产美女高潮| 国产日产一区二区| 精品欧美日韩一区二区| 樱花草在线观看www| 国产在线拍揄自揄拍视频| 国产一级电影网| 中文一区在线观看| 福利视频网站导航| 中文av资源在线| 国产九色porn网址| 在线视频中文字幕久| 国产在线视频自拍| 在线观看精品视频一区二区三区| 久久久久久久久久久久久91| 国产网站在线免费观看| av人人综合网| 国产麻豆精品高清在线播放 | 91九色在线看| 欧美视频免费一区二区三区| 国产午夜电影| 免费a级毛片在线播放| 国产丝袜在线| 超碰在线中文| www.91av| 伊人永久在线| 精品国产免费第一区二区| 中文字幕在线资源| 国内外激情在线| 欧美日韩一区二区三区视视频| 国产女人在线观看| 日本视频在线观看一区二区三区| 国产视频xxxx| 国产精选在线观看| 久久久久久五月天久久久久久久久| 中文资源在线网| 国产精品18久久久久久久久久| 免费在线播放av| www网站在线观看| 四虎一区二区三区| 91精品大全| 国产aⅴ超薄肉色丝袜交足| 国产免费av网站| 国产在线中文字幕| 久蕉依人在线视频| av中文网站| 四虎a级欧美在线观看| 精品黄色免费中文电影在线播放| 国产小视频在线高清播放| 国产精品一区在线看| 久久精品蜜桃| 黄色免费av| 中文字幕在线免费| 国产一级片麻豆| 国产福利热线视频| av免费在线观看网站| 在线免费黄色毛片| 久热国产在线| 最新av免费看| 99久久精品免费观看国产| 香蕉视频在线看| 欧美日韩视频精品二区| 福利视频网站导航| 国产精品福利视频一区二区三区| 国产高清一区二区三区视频| 国产黄色免费网| 日本视频三区| 最新黄网在线观看| 2018狠狠干| 玖玖在线视频| 国产对白叫床清晰在线播放| 精品国产二区三区| 免费a级毛片在线播放| 中文字幕第一页在线| 99在线免费视频| 欧美成人亚洲高清在线观看| 久草视频国产| 在线视频1区2区| 天堂资源最新版在线视频观看免费网| 国产精品伦理一区二区三区| 亚洲男人网站| 96久久久久久| 国产亚洲精品一区二区在线观看| 一本大道香蕉久久| 国产精品美女一区二区视频| 免费在线你懂的|