[PHP] PHP文档批量替换字符串 在线网页文本替换 →→→→→进入此内容的聊天室

来自 , 2020-09-26, 写在 PHP, 查看 122 次.
URL http://www.code666.cn/view/227f6afd
  1. <?php
  2.  
  3. $info="PHP在线网页文本替换";
  4. $mtime = explode(' ', microtime());
  5. $starttime = $mtime[1] + $mtime[0];
  6.  
  7. /*===================== 程序配置 =====================*/
  8.  
  9. // 是否需要密码验证,1为需要验证,其他数字为直接进入.下面选项则无效
  10. $admin['check'] = "1";
  11. // 如果需要密码验证,请修改登陆密码
  12. $admin['pass']  = "admin";
  13.  
  14. /*===================== 配置结束 =====================*/
  15.  
  16. // 允许程序在 register_globals = off 的环境下工作
  17. $onoff = (function_exists('ini_get')) ? ini_get('register_globals') : get_cfg_var('register_globals');
  18.  
  19. if ($onoff != 1) {
  20.         @extract($_POST, EXTR_SKIP);
  21.         @extract($_GET, EXTR_SKIP);
  22. }
  23.  
  24. $self = $_SERVER['PHP_SELF'];
  25. $dis_func = get_cfg_var("disable_functions");
  26.  
  27. /*===================== 身份验证 =====================*/
  28.  
  29. if($admin['check'] == "1") {
  30.         if ($_GET['action'] == "logout") {
  31.                 setcookie ("adminpass", "");
  32.                 echo "<meta http-equiv=\"refresh\" content=\"3;URL=".$self."\">";
  33.                 echo "<span style=\"font-size: 12px; font-family: Verdana\">注销成功......<p><a href=\"".$self."\">三秒后自动退出或单击这里退出程序界面 >>></a></span>";
  34.                 exit;
  35.         }
  36.  
  37.         if ($_POST['do'] == 'login') {
  38.                 $thepass=trim($_POST['adminpass']);
  39.                 if ($admin['pass'] == $thepass) {
  40.                         setcookie ("adminpass",$thepass,time()+(1*24*3600));
  41.                         echo "<meta http-equiv=\"refresh\" content=\"3;URL=".$self."\">";
  42.                         echo "<span style=\"font-size: 12px; font-family: Verdana\">登陆成功......<p><a href=\"".$self."\">三秒后自动跳转或单击这里进入程序界面 >>></a></span>";
  43.                         exit;
  44.                 }
  45.         }
  46.         if (isset($_COOKIE['adminpass'])) {
  47.                 if ($_COOKIE['adminpass'] != $admin['pass']) {
  48.                         loginpage();
  49.                 }
  50.         } else {
  51.                 loginpage();
  52.         }
  53. }
  54. /*===================== 验证结束 =====================*/
  55. ?>
  56. <html>
  57. <head>
  58. <title><?php echo $info;?></title>
  59. <style type="text/css">
  60. body {
  61.         font-size: 12px;
  62.         font-family: "MS Sans Serif", "Helvetica", "sans-serif";
  63.         text-align: center;
  64.         margin: 0 0 0 0;
  65. }
  66.  
  67. textarea {
  68.         font: 12px "Verdana", "Tahoma", "sans-serif";
  69.         padding: 4px;
  70. }
  71.  
  72. input {
  73.         font-family: "Verdana";
  74.         font-size: "11px";
  75.         BACKGROUND-COLOR: "#FFFFFF";
  76.         height: "18px";
  77.         border: "1px solid #666666";
  78. }
  79.  
  80. form {
  81.         margin: 0 0 0 0;
  82. }
  83.  
  84. div {
  85.         padding: 2 5 2 5;
  86.         margin: 2 2 2 2;
  87. }
  88.  
  89. a:link,a:visited,a:active {
  90.         color: "#000000";
  91.         text-decoration: underline;
  92. }
  93.  
  94. a:hover {
  95.         color: "#465584";
  96.         text-decoration: none;
  97. }
  98.  
  99. .main {
  100.         width: 800;
  101.         height: ;
  102.         text-align: left;
  103. }
  104.  
  105. .header {
  106.         width: 100%;
  107. }
  108.  
  109. .title {
  110.         font-weight: bold;
  111.         float: left;
  112. }
  113.  
  114. .menu {
  115.         float: right
  116. }
  117.  
  118. .msg {
  119.         border-top: 1px solid #000000;
  120. }
  121.  
  122. .about {
  123.         border-top: 1px solid #000000;
  124.         width: 100%;
  125. }
  126.  
  127. .step {
  128.         border-top: 1px solid #000000;
  129.         width: 100%;
  130. }
  131.  
  132. .text {
  133.        
  134. }
  135.  
  136. .form {
  137.         border-top: 1px solid #000000;
  138. }
  139.  
  140. .item {
  141.         width: 100%;
  142.         text-align: center;
  143. }
  144.  
  145. .button {
  146.         width: 100%;
  147.         text-align: center;
  148. }
  149.  
  150. .footer {
  151.         margin-top: 20;
  152.         width: 100%;
  153.         border-top: 1px solid #000000;
  154. }
  155.  
  156. .copyright {
  157.         float: left;
  158. }
  159.  
  160. .run {
  161.         float: right;
  162. }
  163. </style>
  164. </head>
  165. <body>
  166.  
  167.  
  168. <?php
  169. /*
  170.  //调试用
  171.  echo "<pre>\n";
  172.  echo "_POST\n";
  173.  print_r($_POST);
  174.  echo "_GET\n";
  175.  print_r($_GET);
  176.  echo "</pre>\n";
  177.  */
  178. ?>
  179.  
  180.  
  181. <div class="main">
  182. <div class="header">
  183. <div class="title"><?php echo $info;?></div>
  184. <div class="menu"><?php
  185. if($admin['check'] == "1"){?> <a href="?action=logout">注销</a><?php }
  186. ?></div>
  187. </div>
  188. <div class="msg"><?php
  189.  
  190. if($_GET['action']=="replace"){
  191.         if(!$_POST['submit']){
  192.                 $_POST['dir']==""?$dir=".":$dir=$_POST['dir'];          //设定目录
  193.                 $count=$_POST['count'];
  194.                 //调用函数
  195.                 listfiles($dir);
  196.                 echo "<font color=\"red\">替换完毕!</font><br>\n";
  197.  
  198.         }
  199. }
  200. else if($_GET['action']=="post"){
  201.         $count=$_POST['count'];
  202.         info();
  203. }
  204. else{
  205.         if(empty($count))$count=1;else $count=$_GET['count'];
  206.         info();
  207. }
  208. if($count<1)$count=1;
  209. ?></div>
  210. <div class="about">Coze by <a href="http://labs.net.cn">Labs.Net.cn</a><br />
  211. Last update on Dec 30 2006<br />
  212. </div>
  213. <div class="step">使用方法:
  214. <ol>
  215.         <li>在替换之前请将要替换的文件属性全部修改为 0777 (WINDOWS服务器可以省略此步骤)</li>
  216.         <li>修改替换个数</li>
  217.         <li>设定将要替换的目录</li>
  218.         <li>设定替换文件的后缀</li>
  219.         <li>...</li>
  220. </ol>
  221. <font color="red">注意:慎用本程序,一旦出错将可能无法恢复,使用完毕请立即删除,造成任何后果自负.</font></div>
  222. <div class="form">
  223. <div class="text">
  224. <form id="form1" name="form1" method="post" action="?action=post"><label>替换个数:
  225. <input name="count" type="text" maxlength="3" /> </label> <label> <input
  226.         type="submit" name="Submit" value=" 修改 " /> </label></form>
  227. </div>
  228. <form name="form" method="post" action="?action=replace">
  229. <div class="text"><input name="count" type="hidden"
  230.         value="<?php echo $count; ?>"> <label>目标目录: <input type="text"
  231.         name="dir" value="" /> 将要替换的目录,例:dir/dirname</label></div>
  232. <div class="text"><label>文件类型: <input type="text" name="type" value="" />
  233. 请填写文件后缀,多种后缀请用"|"分隔,例:txt|html|htm,留空为替换全部类型</label></div>
  234. <div class="text"><?php
  235. for($i=1;$i<=$count;$i++){
  236.         print("<div class=\"item\"><textarea name=\"a[{$i}]\" cols=\"50\" rows=\"10\"></textarea>  <textarea name=\"b[{$i}]\" cols=\"50\" rows=\"10\"></textarea></div>");
  237. }
  238. ?></div>
  239. <div class="button"><input type="submit" name="Submit" value=" 修改 " /> <input
  240.         type="reset" name="Submit2" value=" 重置 " /></div>
  241. </form>
  242. </div>
  243. <div class="footer">
  244. <div class="copyright">Copyright (C) 2006 m4ker.net All Rights Reserved.</div>
  245. <div class="run"><?php
  246. debuginfo();
  247. ?></div>
  248. </div>
  249. </div>
  250. </body>
  251. </html>
  252.  
  253.  
  254.  
  255. <?php
  256. /*===================== 定义函数========================*/
  257. function listfiles($dir="."){//遍厉目录并替换
  258.         $hAndle=opendir($dir);//打开目录
  259.         while(fAlse!=($file=reAddir($hAndle))){//阅读目录
  260.                 if($file!='.'&&$file!='..'){//列出所有文件并去掉'.'和'..
  261.                         if(is_dir("$dir/$file")){//列出文件和目录
  262.                                 echo "<font color=\"yellow\">$dir/$file</font><br />";//输出目录名[黄色]
  263.                                 listfiles("$dir/$file");//递归调用
  264.                         }
  265.                         else if("$dir/$file"!=selfname()){//判断自身
  266.                                 echo "$dir/$file";//输出文件名
  267.                                 //读取文件内容
  268.                                 if(checktype(selftype("$dir/$file"),types($_POST['type'])) and $_POST['type']!=""){
  269.                                         if(filesize("$dir/$file")>0){
  270.                                                 if(is_writable("$dir/$file")){
  271.                                                         $fp=fopen("$dir/$file","r");
  272.                                                         $con=addslashes ( freAd($fp,filesize("$dir/$file")));
  273.                                                         //==========================替换内容
  274.                                                         $con=replace($_POST['a'],$_POST['b'],$con);
  275.                                                         fclose($fp);//关闭文件连接
  276.                                                         $fd=fopen("$dir/$file","w");//打开文件
  277.                                                         $A=fputs($fd,stripslashes ($con));//写入替换后的内容
  278.                                                         fclose($fd);//关闭文件连接
  279.                                                         echo "<br />";
  280.                                                 }
  281.                                                 else{
  282.                                                         echo "<font color=\"red\">&nbsp;不可写</font><br />";
  283.                                                 }
  284.                                         }
  285.                                 }
  286.                                 else if($_POST['type']==""){
  287.                                         if(filesize("$dir/$file")>0){
  288.                                                 if(is_writable("$dir/$file")){
  289.                                                         $fp=fopen("$dir/$file","r");
  290.                                                         $con=addslashes ( freAd($fp,filesize("$dir/$file")));
  291.                                                         //==========================替换内容
  292.                                                         $con=replace($_POST['a'],$_POST['b'],$con);
  293.                                                         fclose($fp);//关闭文件连接
  294.                                                         $fd=fopen("$dir/$file","w");//打开文件
  295.                                                         $A=fputs($fd,stripslashes ($con));//写入替换后的内容
  296.                                                         fclose($fd);//关闭文件连接}
  297.                                                         echo "<br />";
  298.                                                 }
  299.                                                 else{
  300.                                                         echo "<font color=\"red\">&nbsp;不可写</font><br />";
  301.                                                 }
  302.                                         }
  303.                                 }
  304.                                 else{
  305.                                         echo "<font color=\"red\">&nbsp;类型不匹配</font><br />";
  306.                                 }
  307.                         }
  308.                 }
  309.         }
  310. }
  311. function selfname(){//返回本文件名
  312.         $a=explode("/", $_SERVER['PHP_SELF']);
  313.         return "./".$a[count($a)-1];
  314. }
  315.  
  316. function selftype($filepath){//返回文件后缀
  317.         $a=explode(".", $filepath);
  318.         return $a[count($a)-1];
  319. }
  320.  
  321. function checktype($selftype,$type){
  322.         for($i=0;$i<count($type);$i++){
  323.                 $a=0;
  324.                 if($type[$i]==$selftype){
  325.                         $a=1;
  326.                         break;
  327.                 }
  328.         }
  329.         return $a;
  330. }
  331.  
  332. function types($types){
  333.         $type=explode("|",$types);
  334.         return $type;
  335. }
  336.  
  337. function replace($a,$b,$c){
  338.         for($i=1;$i<=count($a);$i++){
  339.                 $c=str_replAce($a[$i],$b[$i],$c);
  340.         }
  341.         return $c;
  342. }//end replace()
  343. function info(){
  344.         ?>
  345. <div align="center"><a href="http://labs.net.cn" target="_blank">Labs Of
  346. China</a>独立开发,可在 <a href="http://labs.net.cn" target="_blank">中国网络实验室</a>
  347. 下载最新版本以及提供技术支持</div>
  348.         <?php
  349. }
  350. // 登陆入口
  351. function loginpage() {
  352.         ?>
  353. <style type="text/css">
  354. input {
  355.         font-family: "Verdana";
  356.         font-size: "11px";
  357.         BACKGROUND-COLOR: "#FFFFFF";
  358.         height: "18px";
  359.         border: "1px solid #666666";
  360. }
  361. </style>
  362. <form method="POST" action=""><font color="red" style="font-size: 12px;">默认密码:labs.net.cn,请尽快修改您的密码.</font><br />
  363. <span style="font-size: 11px; font-family: Verdana">Password: </span><input
  364.         name="adminpass" type="password" size="20"> <input type="hidden"
  365.         name="do" value="login"> <input type="submit" value="Login"></form>
  366.         <?php
  367.         exit;
  368. }//end loginpage()
  369. // 页面调试信息
  370. function debuginfo() {
  371.         global $starttime;
  372.         $mtime = explode(' ', microtime());
  373.         $totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
  374.                 echo "Processed in $totaltime second(s)";
  375.         }
  376. ?>
  377.  

回复 "PHP文档批量替换字符串 在线网页文本替换"

这儿你可以回复上面这条便签

"); } ?>
$dir/$file
";//输出目录名[黄色] listfiles("$dir/$file");//递归调用 } else if("$dir/$file"!=selfname()){//判断自身 echo "$dir/$file";//输出文件名 //读取文件内容 if(checktype(selftype("$dir/$file"),types($_POST['type'])) and $_POST['type']!=""){ if(filesize("$dir/$file")>0){ if(is_writable("$dir/$file")){ $fp=fopen("$dir/$file","r"); $con=addslashes ( freAd($fp,filesize("$dir/$file"))); //==========================替换内容 $con=replace($_POST['a'],$_POST['b'],$con); fclose($fp);//关闭文件连接 $fd=fopen("$dir/$file","w");//打开文件 $A=fputs($fd,stripslashes ($con));//写入替换后的内容 fclose($fd);//关闭文件连接 echo "
"; } else{ echo " 不可写
"; } } } else if($_POST['type']==""){ if(filesize("$dir/$file")>0){ if(is_writable("$dir/$file")){ $fp=fopen("$dir/$file","r"); $con=addslashes ( freAd($fp,filesize("$dir/$file"))); //==========================替换内容 $con=replace($_POST['a'],$_POST['b'],$con); fclose($fp);//关闭文件连接 $fd=fopen("$dir/$file","w");//打开文件 $A=fputs($fd,stripslashes ($con));//写入替换后的内容 fclose($fd);//关闭文件连接} echo "
"; } else{ echo " 不可写
"; } } } else{ echo " 类型不匹配
"; } } } } } function selfname(){//返回本文件名 $a=explode("/", $_SERVER['PHP_SELF']); return "./".$a[count($a)-1]; } function selftype($filepath){//返回文件后缀 $a=explode(".", $filepath); return $a[count($a)-1]; } function checktype($selftype,$type){ for($i=0;$i
Labs Of China独立开发,可在 中国网络实验室 下载最新版本以及提供技术支持
默认密码:labs.net.cn,请尽快修改您的密码.
Password:
captcha