php - preg_replace make matched hex value appear as text -
how use preg_replace convert matching hex values text representation of hex?
$string = 'abcd'.hex2bin(23).'abc'.hex2bin(24);
for example str_replace('/[\x20-\x25]/', 'what here?', $string)
output like:
abcd[hex:23]abc[hex:24]
what want do: i'm looking hidden characters, , want display hex values.
you need preg_replace_callback()
have callback called against matches.
try:
$string = 'abcd'.hex2bin(23).'abc'.hex2bin(24); $text = preg_replace_callback('/[\\x20-\\x25]/', function($matches) { $string = bin2hex($matches[0]); return "[hex:{$string}]"; }, $string);
Comments
Post a Comment