[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] URL encoding



>I'm trying to do URL encoding in a script, just like the browser does
>when it sends a query.
>I'm using :
>        $newchar='%'.hex(unpack("C",$char));
>to encode (which is not correct).
>I tried just hex($char) but that isn't right either.

No -- hex() returns the decimal equivalent of a hexadecimal number. To do
the reverse you need <sprintf("%lx", $num)>. So to get (for instance) the
hex equivalent of a space you would write <sprintf("%lx", ord(' '))> which
would return '20'.

Hope this helps,

Alan Fry