问题描述
好的,我有一个文本文件,并且在文本文件中有以下几行:
Okay so I have a text file and inside of the text file I have these lines:
IP = 127.0.0.1
EXE = Client.exe
PORT = 8080
TITLE = Title
MAINT = False
MAINT-Message = This is the message.
我想做的是在第五行得到假"部分.
what I am wanted to do is get the 'False' part on the fifth line.
我有基本概念,但似乎无法使它起作用.这是我尝试过的:
I have the basic concept but I can't seem to make it work. This is what I have tried:
<?php
$file = file_get_contents('LauncherInfo.txt');
$info = explode(' = ', $file);
echo $info[5];
?>
由此我得到一个结果,但是当我回显$ info [5]时,它给了我'False Maint-Message',因此将其拆分,但仅在=符号处拆分.我希望能够在按Enter进入下一行的位置将其拆分.这可能吗,我该怎么办?
And with this I get a result but when I echo $info[5] it gives me 'False Maint-Message' so it splits it but it only splits at the = sign. I want to be able to make it split at the where I have pressed enter to go onto the next line. Is this possible and how can I do it?
我当时想,如果我让它在第一行爆炸,然后对第二行进行循环操作,直到它到达文件末尾,那还是可以的吗?我不知道该怎么做.
I was thinking it would work if I make it explode on line one and then do the same for the second line with a loop until it came to the end of the file? I don't know how to do this though.
谢谢.
推荐答案
我认为您正在寻找file(),它将文件内容拆分为文件行的数组.
I think you're looking for the file(), which splits a file's contents into an array of the file's lines.
尝试一下:
$file = file('LauncherInfo.txt');
foreach ($file as $line) {
if ($line) {
$splitLine = explode(' = ',$line);
$data[$splitLine[0]] = $splitLine[1];
}
}
echo $data['MAINT'];
这篇关于在PHP中某个字符后阅读文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!