我有一个看起来像这样的网址
http://example.com/index.php?id=111&title=word1 word2 word3
Run Code Online (Sandbox Code Playgroud)
我需要在使用curl请求url之前对空格进行编码.
但是如何urlencode网址的正确部分.
urlencode并rawurlencode编码https问号的斜线等.
您可以使用parse_url()将URL拆分为各自的部分.使用返回的数组中urlencode()的query元素parse_url,然后使用http_build_url将其重新组合在一起.
注意:http_build_url要求PECL pecl_http> = 0.21.0