I known i can get the ASCII code of an character using ord() but i want to encode a string like %45,%20, so i need the HEX code or however it's called
This should do what you want. function str_to_hex($string) { $hex = ''; $len = strlen($string); for ($i = 0; $i < $len; $i++) { $hex .= '%' . str_pad(dechex(ord($string[$i])), 2, 0, STR_PAD_LEFT); } return $hex; } PHP:
In keeping with nico's scheme of things function hex_to_str($hex) { $string = ''; $data = explode('%',$hex); $len = count($data); for ($i=1; $i < $len; $i++) // yes, ONE. skip first array element, which is empty $string .= chr(hexdec($data[$i])); return $string; } PHP: