Hello

I need to URL encode a variable before passing it to a server (xml using curl).
When I just use urlencode($data), it doesn't work.

Help!

Rock

    'doesn't work'
    ... so you say your script crashes completely?

    I dont know what is your issue, but there can be some.
    Read comments at [man]urlencode[/man]

      It needs to be encoded in utf-8... I think urlencode uses another standard?

        According to the people who host the server where my XML request is being sent, the "&" character needs to be converted to "&", but urlencode is giving me "%24".

        Any ideas?

        Rock

          Do not urlencode the entire URL. Instead, just the values of the query string variables, e.g.:

          $url = sprintf(
             'http://www.example.com/webservice.php?var1=%s&var2=%s',
             urlencode($value1),
             urlencode($value2)
          );
          

          Or, if you don't like using sprintf():

          $url = 'http://www.example.com/webservice.php?var1=' .
                 urlencode($value1) . '&var2=' . urlencode($value2);
          
            Write a Reply...