1 <?php
2 /*
3 asp网站快速改版成php网站 小工具
4 QQ496631085
5 XiaoHe
6 */
7 function getExt2($filename)
8 {//分割后缀
9 $ext = strrchr($filename,'.');
10 return $ext;
11 }
12
13 function tihuan1($val)
14 {//替换内容
15 $list=[
16 //<include file="Public:foot" />//替换文件
17 '{aspcms:sitetitle}'=>'<yang:sitetitle />',
18 '{aspcms:companyaddress}'=>'<yang:address />', //地址
19 '{aspcms:companyphone}'=>'<yang:phone />', //联系电话
20 '{aspcms:companyfax}'=>"<yang:cfg name='CFG_FAX' />", //传真
21 '{aspcms:companymobile}'=>"<yang:cfg name='CFG_TEL1' />", //联系手机
22
23 '{aspcms:siteurl}'=>'<yang:siteurl />', //网址
24 '{aspcms:sitekeywords}'=>'<yang:sitekeywords />', //搜索
25 '{aspcms:sitedesc}'=>'<yang:sitedescription />',
26 // '[content:title]'=>'{$list.title}',
27
28 '{aspcms:navlist'=>"<yang:navlist typeid='0'>",//导航——————————需要正则
29 '{/aspcms:navlist}'=>'</yang:navlist>',
30 '{/aspcms:list}'=>'</yang:list>',
31
32 '[news:title]'=>'{$content.title}',//新闻或内容
33 '[news:date]'=>'{$content.publish_time}',
34 '[news:info]'=>'{$content.content}',
35
36 '[list:link]'=>'{$list.url}',
37 '[list:pic]'=>'{$list.litpic}',
38 '[list:title]'=>'{$list.title}',
39
40
41 ];
42 $content=$val;
43 foreach ($list as $old => $new) {
44 $content=str_replace($old,$new,$content);
45 }
46
47 return $content;
48
49 }
50
51
52
53 //获取当前文件所在的绝对目录
54 $dir = dirname(__FILE__);
55 //扫描文件夹
56 $file = scandir($dir);
57 //显示
58
59 // print_r($file);
60 $htmlarr=array(); // 把html文件加入到数组
61 foreach ($file as $key => $name) {
62 if(getExt2($name)=='.html'){
63 array_push($htmlarr,$name);
64 }
65 }
66 $he=0;
67 foreach ($htmlarr as $key1 => $val) {
68
69 $content=file_get_contents($val);
70 $newcontent=tihuan1($content);
71 $fugai=true;//覆盖源文件
72 if($fugai){
73 file_put_contents($val,$newcontent);
74 }else{
75 $dir='newhtml';
76 $dirc = iconv("UTF-8", "GBK", $dir);
77 if (!file_exists($dirc)){
78 mkdirc($dirc,0777,true);
79 echo '创建文件夹'.$dirc.'成功';
80 }
81 // file_put_contents('/newhtml/'.$val,$newcontent);
82 echo '/newhtml/'.$val.'</br>';
83 // echo " <pre>";
84
85 // echo "_______________________________________________________________________</br>";
86 echo "修改{$val}成功";
87 file_put_contents('./newhtml/'.$val,$newcontent);
88 }
89 // $he++;
90
91 }
92
93
94 print_r($htmlarr);
95 ?>