0

This is a little "cut" from the 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),

This is a script I use, to generate a query to the 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/>";
}

The output is following:

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;

The above output, has only one space at the end, but the script is removing all other white spaces, as the name is supposed to be 24 characters count (including the white spaces).

So why is my script removing the white spaces from the end of a name attr?

0

2 Answers 2

6

It's not.

But if you're viewing those queries in your web browser and haven't changed the Content-Type from text/html, then your browser is collapsing whitespaces as it does in HTML.

Either add header("Content-type: text/plain"); to the start of your script (and swap <br/> for \n), or just "View Source" in your browser to see the verbatim output.

Sign up to request clarification or add additional context in comments.

Comments

1

I think it is happening as you have set Content-type as text/html. HTML treats multiple white spaces as one. So try using plain text content type.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.