2016-08-19 3 views
0

Ich habe die nächste txt-DateiWie i var aus txt-Datei in php var verwenden können

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 

und ich möchte dies php var so etwas wie dies verschickt an:

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

ich habe versucht zu explodieren aber es funktioniert nicht ... also wenn du mir helfen könntest wäre das toll!

+0

1) Ich würde ein Array und nicht einzelne Variablen verwenden 2) Werfen Sie einen Blick auf 'preg_match_all()' – Rizier123

+0

Überprüfen Sie diese http://stackoverflow.com/questions/17393369/php-get-value-from-text- Datei – Oncodeeater

Antwort

0

Dies sollte den 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("\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 
?> 

Hoffnung, das hilft!