-1
我需要與爆炸很多線路.txt文件,這些線被描述如下:爆炸僅第一「=」
achievements.levelup.desc=You unlocked the Achievement
achievements.levelup.ok=OK
achievements.levelup.reward=Reward: <b><font size="30" color="#7adde9">%amount%</font></b> %currency_name%
現在的問題是,在第二和第三=
在第三行。
就是它也在這些=
es上爆炸。
如何我現在炸響,是這樣的:
<?php
$array = explode("=", $data, 2);
?>
更新:增加了更多的代碼
的index.php
<?php
require_once('reader.class.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>External Variables Uitlezen</title>
</head>
<body>
<center>
<br><br>
<br><br>
<form action="" method="get">
<label>Hoeveel rijen wil je zien?</label>
<input type="number" name="amount">
<input type="submit" name="enterRows" value="Verder">
</form>
<br><br>
<hr>
<br><br>
<?php
$fileName = "external_flash_texts.txt";
$extReader = new Ext_Var($fileName);
$extReader->SetContent();
if (!isset($_POST['opslaan']) && empty($_POST['opslaan'])) {
if (isset($_GET['enterRows']) && !empty($_GET['enterRows'])) {
echo '<form action="" method="post">';
echo $extReader->GetContent($_GET['amount']);
echo '<input type="submit" name="opslaan" value="Opslaan">';
echo '</form>';
} else {
echo '<form action="" method="post">';
echo $extReader->GetContent(10);
echo '<input type="submit" name="opslaan" value="Opslaan">';
echo '</form>';
}
} else {
$extReader->Save($_POST);
}
?>
</center>
</body>
</html>
reader.class.php
<?php
class Ext_Var {
//File info
private $_fName;
private $_fHandler;
//File content
private $_content = [];
//New file content
private $_newContent;
//Read file
public function __construct($file) {
$this->_fName = $file;
$this->_fHandler = fopen($this->_fName, "r");
}
public function SetContent() {
while ($data = fgets($this->_fHandler)) {
$array = explode("=", $data, 2);
$this->_content[$array[0]] = $array[1];
}
}
public function GetContent($caller) {
$counter = 1;
$content = "";
foreach ($this->_content as $field => $value) {
if ($counter <= $caller) {
$content .= "<p><label>" . $field . "</label> = <input type='text' name='" . $field . "' value='" . $value . "'></p>";
$counter++;
}
}
return $content;
}
public function Save($array) {
if (isset($array) && !empty($array)) {
foreach($this->_content as $field => $value) {
if (isset($array["$field"]) && !empty($array["$field"])) {
$this->_newContent .= $field . "=" . $array["$field"] . "\n";
} else {
$this->_newContent .= $field . "=" . $value;
}
}
if (file_put_contents($this->_fName, $this->_newContent)) {
header("Location: ?msg=Succes");
} else {
echo 'fout';
}
}
}
}
?>
如何閱讀le文件? ...請顯示代碼 – scaisEdge
和你的問題?結果數組是什麼樣的? –
嗯'$ array'我按照你所做的方式做事似乎很好。必須有一個誤解。你'$ array'是什麼? – Mihailo