读取两文件,不同的内容存入另一个文件中
来源:互联网 发布:fedora linux镜像下载 编辑:程序博客网 时间:2024/06/07 20:15
- header("Content-type:text/html;charset=utf-8");
- class Readfiledata {
- /**
- * 链接数据库
- */
- private static function connect(){
- require_once 'index2.php';
- mysql_connect('localhost','root','');
- mysql_select_db('sinapay');
- }
- /**
- * 读文件并获取数据
- */
- private static function getdata($file) {
- $handle = fopen ( $file, 'r' );
- $orderform = array ();
- $i=0;
- while ( false != ($data = fgetcsv ($handle,0,',')) ) {
- $i++;
- if($i==0) continue;
- $orderform [] =trim($data [0],"\t\n\r\0\x0B`\'");
- }
- fclose ( $handle );
- return $orderform;
- }
- /**
- * 获取两个文件不同的数据
- *
- * @param String $file1
- * @param String $file2
- */
- private static function getdiffdata($file1, $file2) {
- $orderform = self::getdata ( $file1 );
- $orderform2 = self::getdata ( $file2 );
- $diff1 = array_diff ($orderform,$orderform2 );
- $diff2 = array_diff ($orderform2,$orderform );
- $todiff = array_merge ( $diff1, $diff2 );
- $todif=array_values(array_unique($todiff));
- return $todif;
- }
- /**
- * 数据写入.csv 文件中
- * @param String $filename
- * @param String $file1
- * @param String $file2
- */
- private static function writefile($filename, $file1, $file2) {
- $todiffdata = self::getdiffdata ( $file1, $file2 );
- $newarray=array();
- self::connect();
- if(empty($todiffdata)){
- echo "两个文件的数据一致";
- die;
- }
- $toparray=array("charge_id","bussined_id");
- $condition='';
- $counarray=count($todiffdata)-1;
- foreach($todiffdata as $key=>$val){
- if($key==$counarray){
- $condition.="charge_id=$val";
- }else{
- $condition.="charge_id=$val or ";
- }
- }
- $sql="select charge_id,business_id from sinapay_charge_final where $condition";
- $result=mysql_query($sql);
- while($res=mysql_fetch_array($result)){
- $data=array('charge_id'=>$res['charge_id'],'business_id'=>$res['business_id']);
- $newarray[]=$data;
- }
- if (! is_file ( $filename)) {
- touch ( $filename);
- }
- $handle = fopen ($filename, 'a' );
- fputcsv($handle, $toparray);
- foreach($newarray as $value){
- fputcsv ( $handle, $value );
- }
- fclose ( $handle );
- }
- /**
- * 入口文件
- */
- public static function main($filename,$file1,$file2) {
- self::writefile ( $filename, $file1, $file2 );
- }
- }
- $filename = 'total.csv';
- $file1 = 'ac.csv';
- $file2 = 'ad.csv';
- Readfiledata::main ($filename, $file1, $file2 );
阅读全文
0 0
- 读取两文件,不同的内容存入另一个文件中
- 读取两文件,不同的内容存入另一个文件中
- c++中读取文件内容存入到另一个文件
- python读取文件内容存入mysql
- 简单的读取文件内容并写到另一个指定的文件中
- linux下,用c语言编程,实现从一个文件读取内容到另一个文件,可以在文件的不同位置修改文件内容,并保存。
- 从一个文件中读取到的内容写到另一个文件中(read,write,open)
- 通过java的io流将本地文件读取到控制台,并将文件内容再次写入另一个文件中
- shell读取文件中的内容,并将其存入到变量中
- 接收一个文件内容,通过读取开始和结束标志,分别将其内容保存到不同的文件中
- java 从一个文件中读取内容 复制到 另一个文件中
- VC++读取文件内容并将其存入二维数组
- Spring框架中读取xml文件的两种不同方式
- 从一个文件读取内容计算出结果,将结果写入到另一个文件中
- IOS中plist文件内容的读取
- MFC 读取文件内容的其中两种方式
- 文件内容的读取
- 读取文件的内容
- Maven详解之仓库------本地仓库、远程仓库
- MVC用filter做权限过滤: 1:创建filter类;类需要继承一个接口,并且重写4个方法;如下: namespace MvcApplication1.Code { public clas
- tensorflow之学习率自衰减的实现
- 14. (多线程)Multithreading
- C# 复习抽象类的使用,模拟移动设备的读写
- 读取两文件,不同的内容存入另一个文件中
- USACO-Section1.3 Mixing Milk
- 80,90后需要提前领悟的至高心法
- 算法导论程序40--贪心算法(活动选择问题)
- 教你快速实现Nexus刷机
- 《SQL反模式》总结
- Bootstrap基本框架
- 个人感悟 动态绑定与静态绑定
- scala多线程demo