我有问题将文本更改为数组
这是文件中的文字:
zkyu,team 3
primesteval,team 2
graves,team 3
我的剪辑;
$file = "test.txt";
$fh = fopen($file, 'r');
$members = array();
$toMoveMem = array();
$i = 0;
while (!feof($fh))
{
$members[] = fgets($fh);
}
fclose($fh);
foreach ($members as $Mem)
{
$MemS = explode(",", $Mem);
$a = ($MemS[0]);
$b = ($MemS[1]);
$c = str_replace("team", "", $b);
array_push($toMoveMem, array("MemberNick" => $a, "MemberTeam" => $c));
}
问题是数组键0和1中奇怪的空行:
Array
(
[0] => Array
(
[MemberNick] => zkyu
[MemberTeam] => 3
)
[1] => Array
(
[MemberNick] => primesteval
[MemberTeam] => 2
)
[2] => Array
(
[MemberNick] => graves
[MemberTeam] => 3
)
)
无法弄清楚我做错了什么。 为什么数组键1和2看起来不像数组键3?
有人可以帮助我并解释一下。
答案 0 :(得分:1)
trim()
上使用$c
。
$c = trim(str_replace("team", "", $b));