Hi, I am not creating the URL, but I parse the URL from XML content and I want to urlencode it. Also, I am looking to preserve all the reserved characters in the URL and not just '?' or '&'.
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Thu, Mar 11, 2010 at 6:59 PM, Don <[email protected]> wrote: > If you use l() or url() the query section is passed separately, so the '?' > and '&' are preserved. The query attributes are passed in an array as > name/value pairs. That's the real drupal way to make a link also. > > -Don- > > > On 3/11/2010 8:23 AM, nitin gupta wrote: > > Hi, > > I am trying to convert a URL to its encoded equivalent. i.e. > http://example.com/path with spaces/ to > http://example.com/path%20with%20spaces/. > > 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 '?', > '#', '=' 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't helping the current situation. > > I thought of the following procedure to achieve the above: > > 1. run rawurldecode on the input url, so that we do not accidentally > encode twice if whole or part of URL is already encoded. > 2. then run rawurlencode, and then preg replace these reserved > characters. > > 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 Feeds Image Grabber <http://drupal.org/project/feeds_imagegrabber> and > Facebook-style > Links <http:///drupal.org/project/facebook_link> module. > > Also, off the subject: shouldn't drupal_http_request() should take care of > such encoding? > > > -- > Regards, > Nitin Kumar Gupta > http://publicmind.in/blog/ > > >
