Question

I was looking for a equivalent function to PHP RawURLEncode (and Decode) in cpp builder (or delphi).

I use the following string to test: _%_&_+_=_ _"_'_a_b_c_d_e_f_g_h_ (I wish to encode only var values, not a entire URL)

The rawurlencode returns: _%25_%26_%2B_%3D_%20_%22_%27_a_b_c_d_e_f_g_h_

I have tried without success:

  • TIdURI::ParamsEncode: _%25_&_+_=_%20_%22_'_a_b_c_d_e_f_g_h_
  • TIdURI::PathEncode: _%25_&_%2B_=_%20_%22_'_a_b_c_d_e_f_g_h_
  • TIdURI::URLEncode: Error: No Protocol (Needs full path)
  • HTTPApp::HTMLEncode: _%_& amp;_+_=_ _& quot;_'_a_b_c_d_e_f_g_h_ (space added after "&")
  • Wininet::WinHTTPEncode: Function not found in unit
  • IdGlobal::URLEncode: Function not found in unit
  • SynaCode::URLEncode: Unit not found in XE2
Was it helpful?

Solution

PHP's RawURLEncode is an implementation of RFC 3986. My websearch for that yields this Delphi unit which claims to implement RFC 3986.

I tested it on your input:

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  UURIEncode in 'UURIEncode.pas';

begin
  Writeln(URIEncode('_%_&_+_=_ _"_''_a_b_c_d_e_f_g_h_'));
  Readln;
end.

The output was:

_%25_%26_%2B_%3D_%20_%22_%27_a_b_c_d_e_f_g_h_

The key to my successful websearch was found in the PHP documentation for RawURLEncode where is states:

URL-encode according to RFC 3986

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top