【发布时间】:2021-07-07 06:39:46
【问题描述】:
我有一个类似的网址
http://example.com/index.php?id=111&title=word1 word2 word3
在使用 curl 请求 url 之前,我需要对空格进行编码。
但是如何对 url 的正确部分进行 urlencode。
urlencode 和rawurlencode 对https 的斜线、问号等进行编码。
【问题讨论】:
-
使用 parse_url 将 URL 分解为其组成部分,然后根据需要对查询字符串进行操作。使用 http_build_url 重新拼接在一起。