dongshaoxiong0012 2016-11-28 10:50
浏览 36
已采纳

我正在研究IP创建形式,并希望爆炸一些数据[关闭]

It's my store method where I am getting IP through request from my view

    public function store(Request $request)
    {
        $ip['ip_range'] = $request->input('ip_range');
        $ip['min_ip']   = $request->input('ip_range');
        $ip['max_ip']   = $request->input('ip_range');

        $ip_data = Ip::create($ip);
        session()->flash('msg', ' Successfully created');
        return view('ip.index');
    }

In above I want if IP comes as

192.168.2.9
192.168.1.2

It should be saved as 2 values .... Mean it should separate it on /r/n and where I found /n I create a new value and so on.

And next thing is that if user enter as

192.168.1.0-3

Here a - comes at last one 192.168.1-3 should be save in ip_range and 192.168.1.0 in min_ip while 192.168.1.3 as max_ip.

  • 写回答

1条回答 默认 最新

  • dounaoji2054 2016-11-28 11:15
    关注

    I hope this is what you were looking for:

    public function store(Request $request) {
        $ip['ip_range'] = $request->input('ip_range');
    
        $arrIps = explode("
    ", $ip['ip_range']);
        foreach($arrIps as $strIp) {
    
            $arrRange=explode("-",$strIp);
            if(count($arrRange)>1){
             $ip['min_ip']= $arrRange[0];
             $arrDot=explode(".",$arrRange[0]);
             $arrDot[3]=$arrRange[1];
             $ip['max_ip']= implode(".",$arrDot);
            }
            else
            $ip['min_ip']=$ip['max_ip']="";
    
            $ip_data = Ip::create($ip);
    
        }
        session()->flash('msg', ' Successfully created');
        return view('ip.index');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加