duanhui3759 2018-06-27 12:48
浏览 40

如何将fgets()的每个输出行存储到单独的变量中?

fgets() shows output is as below =

string(10) "1236457" string(8) "xyz" string(15) "credit:87845 " string(17) "balance:644546 " string(17) "remaining:7463847"

i want to store $var1=1236457 $var2= xyz and same for all.But without using explode.

  • 写回答

1条回答 默认 最新

  • dongwuxie7976 2018-06-27 12:59
    关注

    If you insist on having variables you can iterate the array and create associative keys and then use extract to create the variables.
    In this example I use 0 indexed lines, meaning first line is $line0.

    $arr = explode("
    ", $str);
    Foreach($arr as $key => $val){
       $new["line" . $key] = $val;
    }
    
    Extract($new);
    
    Echo $line2;
    

    https://3v4l.org/psh6H

    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单