Hi,<br><br>I am trying to convert a URL to its encoded equivalent. i.e. <a href="http://example.com/path">http://example.com/path</a> with spaces/ to <a href="http://example.com/path%20with%20spaces/">http://example.com/path%20with%20spaces/</a>.<br>

<br>The problem I am facing is that rawurlencode or urlencode, encodes all the characters and does not show mercy upon the reserved characters such as &#39;?&#39;, &#39;#&#39;, &#39;=&#39; which makes the URL invalid after encoding. I understand that this behavior of these functions is expected considering the fact that they are to be used to encode data (such as query) that can be appended in an URL, but it isn&#39;t helping the current situation.<br>

<br>I thought of the following procedure to achieve the above:<br><ol><li>run rawurldecode on the input url, so that we do not accidentally encode twice if whole or part of URL is already encoded.</li><li>then run rawurlencode, and then preg replace these reserved characters.</li>

</ol>Though it works, I am not sure if it is the correct way to handle this. Any help through ideas or code will be highly appreciated as this will be useful in <a href="http://drupal.org/project/feeds_imagegrabber">Feeds Image Grabber</a> and <a href="http:///drupal.org/project/facebook_link">Facebook-style Links</a> module.<br>

<br>Also, off the subject: shouldn&#39;t drupal_http_request() should take care of such encoding?<br><br><br clear="all">--<br>Regards,<br>Nitin Kumar Gupta<br><a href="http://publicmind.in/blog/">http://publicmind.in/blog/</a><br>