note 50129 deleted from function.preg-replace by felipe

From: Date: Mon, 10 Dec 2007 02:07:14 +0000
Subject: note 50129 deleted from function.preg-replace by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133088@lists.php.net to get a copy of this message
Note Submitter: jhm at cotren dot net ---- It took me a while to figure this one out, but here is a nice way to use preg_replace to convert a hex encoded string back to clear text <?php $text = "PHP rocks!"; $encoded = preg_replace( "'(.)'e" ,"dechex(ord('\\1'))" ,$text ); print "ENCODED: $encoded\n"; ?> ENCODED: 50485020726f636b7321 <?php print "DECODED: ".preg_replace( "'([\S,\d]{2})'e" ,"chr(hexdec('\\1'))" ,$encoded)."\n"; ?> DECODED: PHP rocks!

« previous php.notes (#133088) next »