0

我正在使用这种模式:

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

但这对这个字符串很有用:"c8d3e320c7e1e1f8e520c7e1d1cde3e420c7e1d1cdede3fe"

我想转换字符串,例如:-"\'c8\'d3\'e3\'20\'c7\'e1\'e1\'f8\'e5\'20\'c7\'e1\'d1\'cd\'e3\'e4\'20\'c7\'e1\'d1\'cd\'ed\'e3\'fe"

这意味着任何角色都是从\' 如何改变模式开始的?

谢谢+阿卡姆

使用此模式解决的问题

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

1 回答 1

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
        )

)
于 2013-02-22T21:12:38.253 回答