doupo6967 2017-02-24 15:50
浏览 99
已采纳

PHP结果数据溢出/爆炸,带有赋值

I am new to PHP and working to get some results but failing to achieve my target. I have text file which contains data like this,

APAC|AU|enable|SYD1925|8|20150929|WORKING
APAC|AU|disable|ADL7235|3|20120123|RESIGNED
APAC|NZ|disable|NZ1356|6|20110123|RESIGNED
APAC|NZ|enable|NZ1356|3|20130123|WORKING

I am trying to search "AU" && "enable" for this text, line by line and I am a bit successful in it. Here is my Code example;

public function scan1()
{
    $file = FCPATH.'uploads/example.txt';
    // the following line prevents the browser from parsing this as HTML.
    header('Content-Type: text/plain');
    $search1 = "AU"; 
    $search2 = "enable";
    $lines = file($file); 
    foreach($lines as $line) 
    { 
        if(stristr($line,$search1) && stristr($line,$search2))
            echo $line;
    } 
}

Now, I am trying to explode/split output data and assign variable / array to save in database but I am failing to do so, can someone please help or give me some direction to achieve this. Thank you

  • 写回答

3条回答 默认 最新

  • dongshi1880 2017-02-24 16:01
    关注

    Please show us your_table scheme. If '$db' is a handle of the db connection :

    foreach($lines as $line) 
    { 
        if(stristr($line,$search1) && stristr($line,$search2))
        {
            $arr = explode("|", $line);
            $query = "INSERT INTO your_table VALUES ('".$arr[0]."', '".$arr[1]."', '".$arr[2]."', '".$arr[3]."', '".$arr[4]."', '".$arr[5]."')";
            $db->query($query);
        }
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改