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条)

报告相同问题?