我需要使用PHP,将URL列入密码。
因此,我想在以下几条编码上打字:http://example.com/file name,并由此形成http://example.com/file%20name
。
Of course, if I do urlencode( http://example.com/file name );
then I end up with http%3A%2F%2Fexample.com%2Ffile+name
.
The obvious (to me, anyway) solution is to use parse_url()
to split the URL into scheme, host, etc. and then just urlencode()
the parts that need it like the path. Then, I would reassemble the URL using http_build_url()
.
是否有比这更可取的解决办法? 或者这基本上是走路吗?