Hex Kodunu Metine, Metni Hex Koduna Çevirme

<?php
header('Content-Type: text/html; charset=utf-8');
class Hex{
	var $hex;
	var $tmp;
	function cevirHex($metin){
		$metin=htmlspecialchars_decode($metin);
		foreach(unpack('C*',$metin) as $dec){
			$tmp = dechex($dec);
			$this->hex[] .= strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);	
		}
		return join($this->hex);
	}
	function cevirMetin($hexcode){
		foreach(str_split(trim($hexcode),2) as $hex){
			$this->tmp .= pack('C*', hexdec($hex));
		}
		return htmlspecialchars($this->tmp);
	}
}
$obj = new Hex;
$hexcode = "3C3F706870206563686F20226D6572686162612064C3BC6E7961223B3F3E";
echo $metin=$obj->cevirMetin($hexcode)."<br>";
echo $obj->cevirHex($metin);
?>

Çıktısı

<?php echo "merhaba dünya";?>
3C3F706870206563686F20226D6572686162612064C3BC6E7961223B3F3E3C62723E