CGI code to PHP code help
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.
Code:
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 :)
Re: CGI code to PHP code help
My knowledge of Perl is rather basic, so I'm not sure this is right, but maybe...
Code:
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;
}