0

i am use this pattern:

$line = preg_replace('#(\w)(\w)#e', "chr(hexdec('$1$2'))", $line);

but this useful for this string:"c8d3e320c7e1e1f8e520c7e1d1cde3e420c7e1d1cdede3fe"

and I wanna to conver string for example:- "\'c8\'d3\'e3\'20\'c7\'e1\'e1\'f8\'e5\'20\'c7\'e1\'d1\'cd\'e3\'e4\'20\'c7\'e1\'d1\'cd\'ed\'e3\'fe"

This mean any character started with \' how to change pattern?

thanks +Akam

Problem solved with this pattern

  $line = preg_replace("#\\\'(\w)(\w)#e", "chr(hexdec('$1$2'))", $line);
Mustafa
  • 58
  • 4
  • Just add them in the regex before the two placeholders. Note that each needs backslash escaping, the backslash itself twice. * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Feb 22 '13 at 21:08

1 Answers1

0
$line = "\'c8\'d3\'e3\'20\'c7\'e1\'e1\'f8\'e5\'20\'c7\'e1\'d1\'cd\'e3\'e4\'20\'c7\'e1\'d1\'cd\'ed\'e3\'fe";
echo preg_replace("#\\'(\w)(\w)#e", "chr(hexdec('$1$2'))", $line);

//test
preg_match_all("#\\'(\w)(\w)#e", $line, $out);
echo '<pre>';
print_r($out);

    [1] => Array
        (
            [0] => c
            [1] => d
            [2] => e
            [3] => 2
            [4] => c
            [5] => e
            [6] => e
            [7] => f
            [8] => e
            [9] => 2
            [10] => c
            [11] => e
            [12] => d
            [13] => c
            [14] => e
            [15] => e
            [16] => 2
            [17] => c
            [18] => e
            [19] => d
            [20] => c
            [21] => e
            [22] => e
            [23] => f
        )

    [2] => Array
        (
            [0] => 8
            [1] => 3
            [2] => 3
            [3] => 0
            [4] => 7
            [5] => 1
            [6] => 1
            [7] => 8
            [8] => 5
            [9] => 0
            [10] => 7
            [11] => 1
            [12] => 1
            [13] => d
            [14] => 3
            [15] => 4
            [16] => 0
            [17] => 7
            [18] => 1
            [19] => 1
            [20] => d
            [21] => d
            [22] => 3
            [23] => e
        )

)