duanou2526 2012-06-21 15:40
浏览 75
已采纳

如何在Txt文件中搜索和查找。 然后使用找到的变量

OK, this is Another Project Im Working ON.

Its a Chat Client. and Using it For Staff

I want the server to have a staff.txt on it.

and I want the php file to do this.

Execute the php.

if The Submitted Username is Found in the staff.txt then

The Username changes to [Staff]"Username Here"

I got the search and find down.

I Cant seem to keep the username that was submitted, and just adding staff to it.

Im Adding my Source Now.

<?php
// Parameters (Leave this Alone)
 $Message = $_GET["message"];
 $Username = htmlspecialchars($_GET["username"]);
 $time = ($_GET["time"]);
 // User Banning
 $data = file_get_contents('Banned.txt');
 if(strpos($data, $Username) !== FALSE)
{
   die();
 }
 else
{

 // File Writing (Leave this Alone) 
 $File = "Chat.txt"; 
 $Handle = fopen($File, "a"); 
 fwrite($Handle, $Username);
 fwrite($Handle, ": ");
 fwrite($Handle, $Message);
  fwrite($Handle, " -:-:- ");
  fwrite($Handle, $time);
  fwrite($Handle, "
");
  print "Message Sent"; 
  fclose($Handle); 
 }
?> 

I have user banning working, and i Want the Staff To Work in the same way.

Any Help would be appreciated

Trying it a different way

If ($Username=="!divider!StaffMember1")  $Username="!divider![Staff] StaffMember1"; 
If ($Username=="!divider!StaffMember2")  $Username="!divider![Staff] StaffMember2"; 

that seems to work fine in the php file thats running the php with everything else.

Is there a way to have that list in a seperate file? .txt file or .php doesnt matter.

  • 写回答

1条回答 默认 最新

  • doujiang2641 2012-06-21 15:49
    关注

    You can just do it like the banlist:

    <?php
     // Parameters (Leave this Alone)
     $Message = $_GET["message"];
     $Username = htmlspecialchars($_GET["username"]);
     $time = ($_GET["time"]);
    
    // check staff
     $data = file_get_contents('staff.txt');
     if(strpos($data, $Username) !== FALSE)
         $Username = '[STAFF]' . $Username;
    
    // User Banning
     $data = file_get_contents('Banned.txt');
     if(strpos($data, $Username) !== FALSE)
    {
       die();
     }
     else
    {
    
     // File Writing (Leave this Alone) 
     $File = "Chat.txt"; 
     $Handle = fopen($File, "a"); 
     fwrite($Handle, $Username);
     fwrite($Handle, ": ");
     fwrite($Handle, $Message);
      fwrite($Handle, " -:-:- ");
      fwrite($Handle, $time);
      fwrite($Handle, "
    ");
      print "Message Sent"; 
      fclose($Handle); 
     }
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 论文AlphaTensor复现(有偿)
  • ¥15 (有偿)在ANSYS中 .anf文件
  • ¥45 关于#芯片#的问题:组合逻辑电路设计
  • ¥15 基与机器学习和时间序列分析预测养老服务需求趋势
  • ¥100 求连续两帧图像在水平和垂直上偏移
  • ¥15 mysql全文索引查找指定必须关键词word无效
  • ¥15 Verilog hdl密码锁设计
  • ¥35 基于python的有ssl加密传输的socket聊天室
  • ¥15 数码管亮度控制器设计
  • ¥15 kafka客户端跨网段访问,看日志提示连接的还剩内网地址,且访问不通