一件替换ECMALL翻译文本代码

/ 0评 / 0

引入下PHPExcel

<?php
    include_once "PHPExcel/PHPExcel/IOFactory.php";
    $inputFileName = dirname(__FILE__)."/fy.xlsx";
    $PHPExcel = \PHPExcel_IOFactory::load($inputFileName);
    $data = $PHPExcel->getSheet(0)->toArray();
    $dir = dirname(__FILE__)."/sc-utf-8";

    function get_allfiles($path,&$files) {
        if(is_dir($path)){
            $dp = dir($path);
            while ($file = $dp ->read()){
                if($file !="." && $file !=".."){
                    get_allfiles($path."/".$file, $files);
                }
            }
            $dp ->close();
        }
        if(is_file($path)){
            $files[] =  $path;
        }
    }

    function get_filenamesbydir($dir){
        $files =  array();
        get_allfiles($dir,$files);
        return $files;
    }

    $filenames = get_filenamesbydir($dir);
    //打印所有文件名,包括路径
    foreach ($filenames as $v) {
        $str=file_get_contents($v);
        foreach ($data as $m => $n) {
            $str=str_replace("'".$n[0]."'","'".$n[1]."'",$str);
        }
        file_put_contents($v, $str);
    }


发表评论

电子邮件地址不会被公开。 必填项已用*标注