搬砖仔

  • {{ item.name }}
  • 首页
  • 作品
  • 代码
  • GO
  • 随笔
  • 关于博主
  • 友情链接
  • 文章归档
  • 榜上有名
  • Mail
  • GitHub

一件替换ECMALL翻译文本代码

  • 小酱沫
  • 2019-11-27
  • 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);
    }


© 2023 搬砖仔
Theme by Wing
沪ICP备2021031606号-1 沪公网安备31010402004615号