PDA

Click to See Complete Forum and Search --> : CGI code to PHP code help


lordadel
Dec 2nd, 2009, 04:11 AM
Hello everyone,

I need a favor.

I need to convert this CGI code to PHP code. I don't know about CGI or Perl so i couldn't convert it myself.

sub URL_encode {
my($URL)= @_ ;
$URL=~ s#^([\w+.-]+)://#$1/# ; # http://xxx -> http/xxx
$URL=~ s/(.)/ sprintf('%02x',ord($1)) /ge ; # each char -> 2-hex
$URL=~ tr/a-zA-Z/n-za-mN-ZA-M/ ; # rot-13
return $URL ;
}
I will really appreicate if someone could help me out.

Thanks in advance :)

SambaNeko
Dec 2nd, 2009, 12:43 PM
My knowledge of Perl is rather basic, so I'm not sure this is right, but maybe...

function URL_encode($url){
$url = preg_replace("#^([\w+.-]+)://#","$1/",$url);
$url = preg_replace("/(.)/e"," sprintf('%02x',ord('$1')) ",$url);
$url = str_rot13($url);
return $url;
}