Чтобы преобразовать URL в «первый формат», вы можете использовать функцию PHP urlencode
.
Теперь ответ на вопрос «почему» можно найти в RFC 1738 - Унифицированные указатели ресурсов (URL) .
Цитируя некоторые абзацы:
Octets must be encoded if they have no corresponding graphic
character within the US-ASCII coded character set, if the use of the
corresponding character is unsafe, or if the corresponding character
is reserved for some other interpretation within the particular URL
scheme.
No corresponding graphic US-ASCII:
URLs are written only with the graphic printable characters of the
US-ASCII coded character set. The octets 80-FF hexadecimal are not
used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent
control characters; these must be encoded.
Пробел имеет код% 20 - он не находится в диапазоне 00-1F, поэтому его следует кодировать по этой причине ... Но чуть позже:
Unsafe:
Characters can be unsafe for a number of reasons. The space
character is unsafe because significant spaces may disappear and
insignificant spaces may be introduced when URLs are transcribed or
typeset or subjected to the treatment of word-processing programs.
И здесь вы знаете, почему символ пробела тоже должен быть экранирован / закодирован; -)