搜索
首页php教程php手册php操作XML、读取数据和写入数据的实现代码

这篇文章主要介绍了php操作XML、读取数据和写入数据的实现代码,需要的朋友可以参考下

xml文件

23 开心的路飞 face/43.jpg 123@qq.com 1212121212


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('/(.*)/', $_xml,$_dom); foreach($_dom[1] as $_value){ preg_match_all('/(.*)/', $_value,$_id); preg_match_all('/(.*)/', $_value,$_username); preg_match_all('/(.*)/', $_value,$_sex); preg_match_all('/(.*)/', $_value,$_face); preg_match_all('/(.*)/', $_value,$_email); preg_match_all('/(.*)/', $_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文件中写入数据

/* * _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 = "\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['id']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['username']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['sex']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['face']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['email']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = "\t{$_clean['url']}\r\t"; fwrite($_fp, $_string,strlen($_string)); $_string = ""; fwrite($_fp, $_string,strlen($_string)); flock($_fp,LOCK_UN); fclose($_fp); }

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器