note 50129 added to function.preg-replace

From: Date: Fri, 18 Feb 2005 22:04:52 +0000
Subject: note 50129 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-85230@lists.php.net to get a copy of this message
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! ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50129 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50129&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50129&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50129&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50129&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50129&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50129&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85230) next »