易截截图软件、单文件、免安装、纯绿色、仅160KB

php之XML转数组函数

<?
/**
* 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 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(


相关文档:

怎样才能成为PHP高手?学会"懒惰"的编程

      PHP是一门高效的网络编程语言,由于它具有编写灵活、运行快速等优点,迅速成为Web程序员的首选语言。前不久的一份权威调查表明,现在已经有31.6%的网站使用PHP作为主要的服务器端编程语言。
  但是,要成为一名PHP编程高手却并不容易。并不像很多人想象的那样,只要能够飞快地编写 ......

php session配置

php session配置
2009-12-02 09:58
[Session]
; 除非使用session_register()或$_SESSION注册了一个变量。
; 否则不管是否使用了session_start(),都不会自动添加任何session记录。
; 包括resource变量或有循环引用的对象包含指向自身的引用的对象,不能保存在会话中。
; register_globals指令会 ......

PHP基本语法


标准代码如下:
<?php
...
?>
短标签模式(此模式需要修改PHP配置,让PHP支持短标签模式):
<?
...
?>
注释:
/* ...*/
//
#

其它:
在php中用";"来分隔语句。
例句:
<?php
echo "Hello World!"
?>
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号