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(
相关文档:
(IT柏拉图 原创文章)如果只是unicode转utf-8编码的算法,网上到处都是了,不过很多人也是你抄我,我抄你,根本就不理解why和do,本文除了给出最简单的php对unicode转utf-8编码函数之外,也深入讨论了这两种编码的关系,理解好了会发现网上一些旧的东西,是严重多余兼过期的,因为从utf-8流行开始到现在,早已经由原来六字节 ......
php调用oracle行存储过程############################################################
PHP程序访问数据库,完全可以使用存储过程,有人认为使用存储过程便于维护
不过仁者见仁,智者见智。
在这个问题上,偶认为使用存储过程意味着必须要DBA和开发人员更紧密配合,如果其中一方更变,则显然难以维护。
但是使用存储 ......
因为项目需要,所以自己写了一个CRUD类
虽然还比较简单,不过感觉很实用。
注:cls_database是一个数据库操作类
见:http://code.google.com/p/cyy0523xc/source/browse/trunk/php/cls_crud.php
<?php
/**
* 自动化数据表操作类
* @author 小蔡 <cyy0523xc@gmail.com>
* @version 1.0
*/
class cls_ ......
标准代码如下:
<?php
...
?>
短标签模式(此模式需要修改PHP配置,让PHP支持短标签模式):
<?
...
?>
注释:
/* ...*/
//
#
其它:
在php中用";"来分隔语句。
例句:
<?php
echo "Hello World!"
?>
......
<?
* +-------------------------------------------------------------+
* | Copyright (c) 2008-2009 Diqiye.Com All rights reserved.
* +-------------------------------------------------------------+
* | Info : 图像处理类
* +------------------------------------------------------------ ......