我怎样才能将txt文件中的var用于php var

时间:2016-08-19 22:30:41

标签: php file

我有下一个txt文件

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

我想把这个发送到php var这样的东西:

$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";

我试图使用爆炸,但它不起作用......所以,如果你可以帮助我那将是伟大的!

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

<?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("\r\n", $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
?>

希望有所帮助!