preg_replace_callback():编译失败:PCRE不支持

时间:2014-03-06 02:01:16

标签: php regex preg-replace

我有这样的事情:

$fbVideosContent = '\u00257B\u002522autoplay\u002522\u00253Atrue\u00252C\u002522autorewind\u002522\u00253Atrue\u00252C\u002522default_hd\u002522\u00253Afalse\u00252C\u002522dtsg\u002522\u00253A\u002522AQAXntRU\u002522\u00252C\u002522inline_player\u002522\u00253Afalse\u00252C\u002522lsd\u002522\u00253A\u002522AVo8F63M\u002522\u00252C\u002522min_progress_update\u002522\u00253A300\u00252C\u002522pixel_ratio\u002522\u00253A1\u00252C\u002522preload\u002522\u00253Afalse\u00252C\u002522source\u002522\u00253A\u002522permalink\u002522\u00252C\u002522start_index\u002522\u00253A0\u00252C\u002522start_muted\u002522\u00253Afalse\u00252C\u002522use_spotlight\u002522\u00253Afalse\u00252C\u002522video_data\u002522\u00253A\u00255B\u00257B\u002522hd_src\u002522\u00253A\u002522https\u00253A\u00255C\u00252F\u00255C\u00252Ffbcdn-video-a.akamaihd.net\u00255C\u00252Fhvideo-ak-prn2\u00255C\u00252Fv\u00255C\u00252Ft43\u00255C\u00252F1220287_589416207790149_21015_n.mp4\u00253Foh\u00253D2cabdd6d73d4777fd8c645ab8283d517\u002526oe\u00253D5317F0E5\u002526__gda__\u00253D1394076748_489a19e4834fa38ba484f77977d496c8\u002522\u00252C\u002522is_hds\u002522\u00253Afalse\u00252C\u002522index\u002522\u00253A0\u00252C\u002522rotation\u002522\u00253A0\u00252C\u002522sd_src\u002522\u00253A\u002522https\u00253A\u00255C\u00252F\u00255C\u00252Ffbcdn-video-a.akamaihd.net\u00255C\u00252Fhvideo-ak-prn2\u00255C\u00252Fv\u00255C\u00252Ft42\u00255C\u00252F1305106_594539630611140_37914_n.mp4\u00253Foh\u00253D8a004ce7f5d600a19516c0d94c24ed5e\u002526oe\u00253D5317F2B3\u002526__gda__\u00253D1394077146_74fa388b2f1440593ee4a4acb4af1421\u002522\u00252C\u002522thumbnail_src\u002522\u00253A\u002522https\u00253A\u00255C\u00252F\u00255C\u00252Ffbcdn-vthumb-a.akamaihd.net\u00255C\u00252Fhvthumb-ak-prn1\u00255C\u00252Ft15\u00255C\u00252F158098_134378089960632_134376349960806_24350_1435_b.jpg\u002522\u00252C\u002522thumbnail_height\u002522\u00253A352\u00252C\u002522thumbnail_width\u002522\u00253A640\u00252C\u002522video_duration\u002522\u00253A99\u00252C\u002522video_id\u002522\u00253A\u002522134376349960806\u002522\u00257D\u00255D\u00257D';

并希望“反混淆”它。

我做了:

    $fbVideosContent = preg_replace_callback(
        '/\\u([\d\w]{4})/',
        function($matches) {
            $unicodeChar = '\u' . $matches[1];
            return json_decode('"'.$unicodeChar.'"');
        },


        $fbVideosContent
    );

不幸的是我得到了:

  

preg_replace_callback():编译失败:PCRE不支持\ L,   \ l,\ N {name},\ U或\ u在偏移量1

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

来自here

PCRE does not support the \uXXXX syntax. Use \x{XXXX} instead.

答案 1 :(得分:0)

您必须双重转义引号(或三元组)内的反斜杠才能获得文字反斜杠:

'/\\\u([\d\w]{4})/'

"/\\\\u([\d\w]{4})/"