download2014711 2016-08-19 22:30
浏览 23
已采纳

我如何使用var从txt文件到php var

i have the next txt file

Value:
00:c2:75:06:18:aa:6b:26:7c:1a:fa:d0:03:36:4c: 
31:ca:3a:0f:3c:0a:e6:f3:54:20:d6:2a:77:1a:e5: 
71:5b:11:ce:2d:28:bf:19:ed:58:96:fc:62:24:e2:da:31:b0:4f:3d 

Mod:7b:64:7d:bd:ae:84:ce:1a:01:9d:3a:
7d:2a:20:ae: 64:44:16:27:16:51:f7:e0:f9:96:
35:7c:6a:ca:8a:15:26:be:99:73:00:2c:aa:62:
73:fb:97:6e:f7:54: 97:29:44:51 

Foo: 0e:31:dc:b7:12:39:a0:25:8f:12:9f:
fc:9c:0a:14: ce:a6:d6:90:09:33:36:ed:4c:5c:
e5:7f:f7:09:ed: d8:85:44:77:6d:94:4e:4e:e5:
d6:bc:62:d5:63:ca:dd:87:b1:41

and i want to sent this to php var something like this:

$value= "00:c2:75:06:18:aa:6b:26:7c:1a:fa:d0:03:36:4c: 
         31:ca:3a:0f:3c:0a:e6:f3:54:20:d6:2a:77:1a:e5: 
         71:5b:11:ce:2d:28:bf:19:ed:58:96:fc:62:24:e2:
         da:31:b0:4f:3d ";

$mod="7b:64:7d:bd:ae:84:ce:1a:01:9d:3a:
7d:2a:20:ae: 64:44:16:27:16:51:f7:e0:f9:96:
35:7c:6a:ca:8a:15:26:be:99:73:00:2c:aa:62:
73:fb:97:6e:f7:54: 97:29:44:51 ";

$Foo="0e:31:dc:b7:12:39:a0:25:8f:12:9f:
fc:9c:0a:14: ce:a6:d6:90:09:33:36:ed:4c:5c:
e5:7f:f7:09:ed: d8:85:44:77:6d:94:4e:4e:e5:
d6:bc:62:d5:63:ca:dd:87:b1:41";

i've tried to use explode but it doesn't work ... so if you could help me that would be great!

  • 写回答

1条回答 默认 最新

  • duanliao6789 2016-08-19 23:16
    关注

    This should do the trick:

    <?php
    
    // Get the contents of the using file_get_contents
    $file_content = file_get_contents('next.txt');
    
    // convert the file to an array containing lines
    $lines = explode("
    ", $file_content);
    
    // Extract the Value and remove the "Value:" part
    $value = str_ireplace("value:", "", $lines[0]); // 1st line
    
    // Extract the Mod
    $mod = str_ireplace("mod:", "", $lines[1]); // 2nd line
    
    // Extract the Food
    $foo = str_ireplace("foo:", "", $lines[2]); // 3rd line
    ?>
    

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错