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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -