xml文件
<?xml version="1.0" encoding="utf-8"?> <vip> <id>23</id> <username>开心的路飞</username> <sex>男</sex> <face>face/43.jpg</face> <email>123@qq.com</email> <qq>1212121212</qq> </vip>
php解析XML获取标签中的值
/*
* _get_xml 获取的XML文件
* @access public 表示函数对外公开
* @param $_xmlfile xml文件
* $_html 从XML中取出的数据数组
* */
function _get_xml($_xmlfile){
$_html = array();
if(file_exists($_xmlfile)){
$_xml = file_get_contents($_xmlfile);
preg_match_all('/<vip>(.*)<\/vip>/', $_xml,$_dom);
foreach($_dom[1] as $_value){
preg_match_all('/<id>(.*)<\/id>/', $_value,$_id);
preg_match_all('/<username>(.*)<\/username>/', $_value,$_username);
preg_match_all('/<sex>(.*)<\/sex>/', $_value,$_sex);
preg_match_all('/<face>(.*)<\/face>/', $_value,$_face);
preg_match_all('/<email>(.*)<\/email>/', $_value,$_email);
preg_match_all('/<qq>(.*)<\/qq>/', $_value,$_qq);
$_html['id'] = $_id[1][0];
$_html['username'] = $_username[1][0];
$_html['sex'] = $_sex[1][0];
$_html['face'] = $_face[1][0];
$_html['email'] = $_email[1][0];
$_html['qq'] = $_qq[1][0];
}
}else{
_alert_back("文件不存在");
}
return $_html;
}php向XML文件中写入数据
初阶PHP Apache MySQL网站设计来自作者多年学习、应用和讲授PHP的经验与体会,是专为学习PHP+MySQL数据库编程人员编与的入门教材。在最后二章设计了2个贴近实际应用的典型案例:留言本系统和论坛系统,每个案例先介绍开发思路、步骤,再给出全部源代码,使所学内容与实际应用紧密结合,特别是论坛系统将全书的案例串讲起来,力求使读者学到最贴近应用前沿的知识和技能。
377
/*
* _set_xml将信息写入XML文件
* @access public 表示函数对外公开
* @param $_xmlfile xml文件
* @param $_clean 要写入的信息的数组
* */
function _set_xml($_xmlfile,$_clean){
$_fp = @fopen('newuser.xml','w');
if(!$_fp){
exit('系统错误,文件不存在!');
}
flock($_fp,LOCK_EX);
$_string = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "<vip>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<id>{$_clean['id']}</id>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<username>{$_clean['username']}</username>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<sex>{$_clean['sex']}</sex>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<face>{$_clean['face']}</face>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<email>{$_clean['email']}</email>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "\t<qq>{$_clean['url']}</qq>\r\t";
fwrite($_fp, $_string,strlen($_string));
$_string = "</vip>";
fwrite($_fp, $_string,strlen($_string));
flock($_fp,LOCK_UN);
fclose($_fp);
}
在网上找的一点资料 希望能帮到你php中对xml读取的相关函数的介绍:引用:--------------------------------------------------------------------------------对象 XML解析函数 描述
元素 xml_set_element_handler() 元素的开始和结束
字符数据 xml_set_character_data_handler() 字符数据的开始
外部实体 xml_set_external_entity_ref_handler() 外部实体出现
未解析外部实体 xml_set_unparsed_entity_decl_handler() 未解析的外部实体出现
处理指令 xml_set_processing_instruction_handler() 处理指令的出现
记法声明 xml_set_notation_decl_handler() 记法声明的出现
默认 xml_set_default_handler() 其它没有指定处理函数的事件--------------------------------------------------------------------------------下面就给大家举一个小小的例子用parser函数来读取xml数据:$parser = xml_parser_create(); //创建一个parser编辑器
xml_set_element_handler($parser, "startElement", "endElement");//设立标签触发时的相应函数 这里分别为startElement和endElenment
xml_set_character_data_handler($parser, "characterData");//设立数据读取时的相应函数
$xml_file="1.xml";//指定所要读取的xml文件,可以是url
$filehandler = fopen($xml_file, "r");//打开文件
while ($data = fread($filehandler, 4096))
{
xml_parse($parser, $data, feof($filehandler));
}//每次取出4096个字节进行处理fclose($filehandler);
xml_parser_free($parser);//关闭和释放parser解析器
$name=false;
$position=false;
function startElement($parser_instance, $element_name, $attrs) //起始标签事件的函数
{
global $name,$position;
if($element_name=="NAME")
{
$name=true;
$position=false;
echo "名字:";
}
if($element_name=="POSITION")
{$name=false;
$position=true;
echo ......余下全文>>
我的思路是,直接使用动态的xml,让flash读取这个文档,这样就不用实时的去生成xml文件了。当然,这个xml文件是.php格式的,所以你必须在flash中吧读取的文件地址改成php的,就跟你写一个php页面一样,不同的是这个php文件输出的内容是一个xml格式的文本。
比如你现在建立文件 xml.php
echo "
//若此处也有动态信息 按需要进行调用
echo"
//在此循环你的图片数据
$data = ??
while( $data ) {
echo "
}
echo '';
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号