这是 data.txt 中的一个小“剪辑”:
(7220, 'Miecz Swiatla Ksiezyca +', 'Miecz Swiatla Ksiezyca +', 1, 0, 0, 2, 32, 1, 16, '', 30000, 100, 7221, 19, 0, 5, 1, 80, 0, 0, 7, 15, 17, 2, 0, 0, 0, 90, 110, 5, 67, 117, -1, -1, -1, -1, -1, -1, 0, 3, -1),
(2, 'ŔÎĹͳ׼ųÎ070905-121713 ', 'Polska Wersja', 0, 0, 0, 1, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0),
(10, 'µµ+0 ', 'Miecz +0', 1, 0, 0, 2, 32, 1, 16, '', 0, 0, 11, 1, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 0, -1, -1, -1, -1, -1, -1, 0, 1, 0),
(11, 'µµ+1 ', 'Miecz +1', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 12, 2, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 7, -1, -1, -1, -1, -1, -1, 0, 1, 0),
(12, 'µµ+2 ', 'Miecz +2', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 13, 3, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 14, -1, -1, -1, -1, -1, -1, 0, 1, 0),
(13, 'µµ+3 ', 'Miecz +3', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 14, 4, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 21, -1, -1, -1, -1, -1, -1, 0, 1, 0),
(14, 'µµ+4 ', 'Miecz +4', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 15, 5, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 28, -1, -1, -1, -1, -1, -1, 30, 1, 0),
(15, 'µµ+5 ', 'Miecz +5', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 16, 6, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 35, -1, -1, -1, -1, -1, -1, 40, 1, 0),
(16, 'µµ+6 ', 'Miecz +6', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 17, 7, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 42, -1, -1, -1, -1, -1, -1, 50, 1, 0),
(17, 'µµ+7 ', 'Miecz +7', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 18, 8, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 49, -1, -1, -1, -1, -1, -1, 65, 1, 0),
(18, 'µµ+8 ', 'Miecz +8', 1, 0, 0, 2, 32, 1, 16, '', 100, 0, 19, 9, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 56, -1, -1, -1, -1, -1, -1, 80, 1, 0),
(19, 'µµ+9 ', 'Miecz +9', 1, 0, 0, 2, 32, 1, 16, '', 2000, 0, 0, 0, 0, 15, 1, 0, 0, 0, 7, 22, 0, 0, 0, 0, 0, 15, 19, 13, 15, 63, -1, -1, -1, -1, -1, -1, 100, 1, 0),
这是我使用的脚本,用于生成对以下内容的查询MySQL
:
header('Content-type: text/html; charset=windows-1250');
$data = file("data.txt"); // returns an array of the lines
foreach($data as $key => $val){
$temp = explode(',', $val);
$id = substr($temp[0], 1);
$name = $temp[1];
$query = 'UPDATE `item_proto`
SET `name` = ' . $name . '
WHERE `vnum` = ' . $id . ';';
echo $query."<Br/>";
}
输出如下:
UPDATE `item_proto` SET `name` = 'Miecz Swiatla Ksiezyca +' WHERE `vnum` = 7220;
UPDATE `item_proto` SET `name` = 'ŔÎĹͳ׼ųÎ070905-121713 ' WHERE `vnum` = 2;
UPDATE `item_proto` SET `name` = 'µµ+0 ' WHERE `vnum` = 10;
UPDATE `item_proto` SET `name` = 'µµ+1 ' WHERE `vnum` = 11;
UPDATE `item_proto` SET `name` = 'µµ+2 ' WHERE `vnum` = 12;
UPDATE `item_proto` SET `name` = 'µµ+3 ' WHERE `vnum` = 13;
UPDATE `item_proto` SET `name` = 'µµ+4 ' WHERE `vnum` = 14;
UPDATE `item_proto` SET `name` = 'µµ+5 ' WHERE `vnum` = 15;
UPDATE `item_proto` SET `name` = 'µµ+6 ' WHERE `vnum` = 16;
UPDATE `item_proto` SET `name` = 'µµ+7 ' WHERE `vnum` = 17;
UPDATE `item_proto` SET `name` = 'µµ+8 ' WHERE `vnum` = 18;
UPDATE `item_proto` SET `name` = 'µµ+9 ' WHERE `vnum` = 19;
上面的输出最后只有一个空格,但脚本正在删除所有其他空格,因为name
应该是 24 个字符(包括空格)。
那么为什么我的脚本会从name
attr 末尾删除空格?