doubinchou4219 2012-03-30 02:46
浏览 12
已采纳

php打开,读取,传入/从mysql数据库传输

I've read some posts where a php file opens and writes the info to a database. But it has a delimeter such as | or , or ..

However, I have a txt file that deals with numbers and the delimter is a space between numbers.

For example user 1 with userlevel of site 12 and admin status of 12:

977970 12 12

Another example of multiple users:

977970 password 12 12
100490 password 3  12

Each new line is a new user with their indiviual details.

And the second half to this, is that it needs to update the text file with new users. I'm sure the update will need a cron job running.

  • 写回答

2条回答 默认 最新

  • donglong7338 2012-03-30 03:24
    关注

    If i understood the problem right. You are trying to read from a file and store it into a database where your records are delimited by space & I haven't checked the code but it should work or at least give you an idea

    <?php
        $data = Array();
        $handle = @fopen("/Your/File.txt", "r");  
        if ($handle) {
           while (($line = fgets($handle)) !== false) {
              $data[]= $line;                    // read each line and store in array
           }
           if (!feof($handle)) {
               echo "Error";
           }
           fclose($handle);
           getDelimitedVals($data);
       }
    

    your function to separate the record

       function getDelimitedVals($data) {
           if(empty($data)) {
               return false;
           }
           foreach($data as $line) {
               $dbData[] = explode(" ", $line);     // this will separate the uname, pwd, id and store in new arry
           }
    
           return dbData;
       }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题