zoukankan      html  css  js  c++  java
  • PHP读写文件

    一:读取文件

    例1:

        $xml = "";
        //打开文件
        $f = fopen('http://app.eyuebus.com/Public/apk/version.xml', 'r');
        //循环读取文件的全部内容,每次读取4096个字符
        while( $data = fread( $f, 4096 ) ) {
            $xml .= $data;
        }  
        //关闭一个打开文件
        fclose( $f );

    例2:读取xml文件,用php正则表达式来记取数据

    $xml = ""; 
    $f = fopen('person.xml', 'r'); 
    while( $data = fread( $f, 4096 ) ) { 
    $xml .= $data; 
    } 
    fclose( $f ); 
    // 上面读取数据 
    preg_match_all( "/<humans>(.*?)</humans>/s", $xml, $humans ); //匹配最外层标签里面的内容 
    foreach( $humans[1] as $k=>$human ) 
    { 
    preg_match_all( "/<name>(.*?)</name>/", $human, $name ); //匹配出名字 
    preg_match_all( "/<sex>(.*?)</sex>/", $human, $sex ); //匹配出性别 
    preg_match_all( "/<old>(.*?)</old>/", $human, $old ); //匹配出年龄 
    } 
    foreach($name[1] as $key=>$val){ 
    echo $val." - ".$sex[$key][1]." - ".$old[$key][1]."<br>" ; 
    } 
  • 相关阅读:
    os.remove some jpgs
    shutil.rmtree, os.path, delete sub-folders, format
    How to create folder
    valgrind
    gstream
    TP TN FP FN
    tensor flow
    接口中静态方法和默认方法
    JAVA基础09
    JAVA基础08
  • 原文地址:https://www.cnblogs.com/wangyuman26/p/5779407.html
Copyright © 2011-2022 走看看