2022-01-18

正则匹配导入csv

$str = file_get_contents('./171771.csv');
       preg_match_all('/xxx.xxx.com\\\\\/case(.*?)(\.mp3|\.wav|\.png|\.jpg|\.m4a|\.wma|\.amr)/is', str_replace(["\r\n","\n","\r"], '', $str), $matches);
       //var_dump($matches);
        //echo '路径,文件名,文件类型<br/>';
        file_put_contents('./171771_new.csv', "路径,文件名,文件类型,\n");
       foreach ($matches[0] as $match) {
           $match = str_replace(['xxx.xxx.com\/', '\/'], ['', '/'], $match);
           $arr = explode('.', $match);
           $arr2 = explode('/', $match);
           //echo  $match . ',' . end($arr2) . ',' . end($arr) . ',<br/>';
           file_put_contents('./171771_new.csv', $match . ',' . end($arr2) . ',' . end($arr) . ",\n", FILE_APPEND);
       }

发表回复

Your email address will not be published. Required fields are marked *