How do I avoid URL globbing with PHP cURL?

[亡魂溺海] 提交于 2019-12-06 02:28:08

Currently I'm using this and it seems to work

$urlReconstructed = str_replace(']', '%5D', str_replace('[', '%5B', $url));

This seems to work for me:

$urlParts = parse_url($url);    
parse_str($urlParts['query'], $queryParts);
$urlReconstructed = sprintf('%s://%s%s?', $urlParts['scheme'], $urlParts['host'], $urlParts['path']);

foreach ($queryParts as $key => $value)
{
  $urlReconstructed .= $key . "=" . urlencode($value);
}

echo $urlReconstructed;

Thanks Pekka, Convert your comment to an answer. If no other better answers pop up i will award you the correct answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!