簡體   English   中英

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

[英]How can i use var from txt file to php var

我有下一個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";

我試過使用explode,但是它不起作用...所以,如果您能幫助我,那將是很棒的!

這應該可以解決問題:

<?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
?>

希望有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM