这是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?
答案 0 :(得分:6)
不是。
但是,如果您在网络浏览器中查看这些查询并且未从text/html
更改内容类型,则您的浏览器会像在HTML中那样折叠空格。
将header("Content-type: text/plain");
添加到脚本的开头(并为<br/>
交换\n
),或在浏览器中添加“查看源代码”以查看逐字输出。
答案 1 :(得分:1)
我认为这已经发生,因为您已将Content-type
设为text/html
。 HTML将多个空格视为一个空格。因此,请尝试使用纯文本内容类型。