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

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)