NotionCommotion Posted June 24, 2016 Share Posted June 24, 2016 I wish to urlencode part of a URL, and can do the following: sendIt("/cars/".urlencode("Model T")); function sendIt($u) { $ch = curl_init("http://forums.phpfreaks.com{$u}"); } Instead, I wish to put the urlencode statement in the function as follows. sendIt("/cars/Model T"); function sendIt($u) { $ch = curl_init("http://forums.phpfreaks.com".urlencode($u)); } Problem is that it encodes the forward slashes. How can this be done? Quote Link to comment https://forums.phpfreaks.com/topic/301395-using-urlencode/ Share on other sites More sharing options...
Solution Jacques1 Posted June 24, 2016 Solution Share Posted June 24, 2016 The second code snippet doesn't make a lot of sense, because you're blindly applying urlencode() to a complete part of the URL. This will not only fudge up forward slashes. A query or fragment will also be affected. You need to apply the encoding while you assemble the URL or URL part so that you know exactly what you encode (e. g. an individual path segment or parameter). Quote Link to comment https://forums.phpfreaks.com/topic/301395-using-urlencode/#findComment-1534011 Share on other sites More sharing options...
NotionCommotion Posted June 24, 2016 Author Share Posted June 24, 2016 Bummer. I was hoping I could be more lazy. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/301395-using-urlencode/#findComment-1534012 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.