一件替换ECMALL翻译文本代码
引入下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);
}