webForumDet fria alternativet

PHP hata Delphi?

2 svar · 207 visningar · startad av Jontto

JonttoMedlem sedan okt. 2001125 inlägg
#1

Började just programmera i Delphi (2 dagen på gång re'n), å funderade om man på något sätt kan "urldecoda" något som man har urlencodat med PHP och urlencoda text tillbaka oxå?

Tacksam för svar,
Jontto

jtMedlem sedan juni 2000350 inlägg
#2

Testa dessa funktioner.

function URLDecode(ASrc: string): string;
var
i: integer;
ESC: string[2];
CharCode: integer;
begin
Result := '';
ASrc := StringReplace(ASrc, '+', ' ', [rfReplaceAll]); {do not localize}
i := 1;
while i <= Length(ASrc) do begin
if ASrc *<> '%' then begin {do not localize}
Result := Result + ASrc
*end else begin
Inc(i); // skip the % char
ESC := Copy(ASrc, i, 2); // Copy the escape code
Inc(i, 1); // Then skip it.
try
CharCode := StrToInt('$' + ESC); {do not localize}
if (CharCode > 0) and (CharCode < 256) then begin
Result := Result + Char(CharCode);
end;
except end;
end;
Inc(i);
end;
end;

function URLEncode(ASrc: string): string;
const
UnsafeChars = ['*', '#', '%', '<', '>', '+']; {do not localize}
var
i: Integer;
begin
Result := '';
for i := 1 to Length(ASrc) do begin
if ASrc = ' ' then begin {do not localize}
Result := Result + '+'; {do not localize}
end else if (ASrc in UnsafeChars) or (ASrc >= #$80) then begin
Result := Result + '%' + IntToHex(Ord(ASrc
), 2); {do not localize}
end else begin
Result := Result + ASrc
;
end;
end;
end;
******

PeWMedlem sedan juni 200010 432 inlägg
#3

Hade varit trevligt om man använder kodtaggarna när man postar kod... :OO

125 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
123 ms — hämta tråd, inlägg och bilagor (db)