0

I have a string like:$str='&%#^*@\"~ \'a4{=s{sa*}7s*&$db{abc654d3ws67}d(*$%#$c6'#^*@"~ \'a4\"'; .

I need to find what is not like {abc654d3ws67} as $needle from that string and preplace it by bin2hex($needle).

Example: bin2hex('#').

4

2 に答える 2

3

のすべての出現箇所を検索し{、その後に任意の数の文字または数字が続き、その後に}.

$str = preg_replace_callback( '/\{([^a-z0-9]+)\}/i', function( $match) { 
    return bin2hex( $match[1]); 
}, $str);
于 2013-05-24T02:17:52.647 に答える