function sk_pattern2unicode($pattern, $from_enc = 'ISO-8859-1') { $patt[] = '/(?<!\\x5C)\\x5Cw/'; $repl[] = '\\p{L}'; $patt[] = '/(?<!\\x5C)\\x5CW/'; $repl[] = '\\p{^L}'; $patt[] = '/(?<!\\x5C)\\x5Cs/'; $repl[] = '\\p{Zs}'; $patt[] = '/(?<!\\x5C)\\x5CS/'; $repl[] = '\\p{^Zs}'; if (is_string($pattern)) { return @iconv($from_enc, 'UTF-8', preg_replace($patt, $repl, $pattern)) . 'u'; } elseif (is_array($pattern)) { foreach ($pattern as $key => $val) { $pattern[$key] = sk_pattern2unicode($val, $from_enc); } return $pattern; } else { return false; } }
/** * parse config string * @param $str * @param bool $is_unicode * @return array */ function sk_parse_config_str($str, $is_unicode = false) { $patt[] = '/&SCREENEDSPACE&/'; $repl[] = ' '; $patt[] = '/&SCREENEDLFEED&/'; $repl[] = "\n"; $patt[] = '/&SCREENSNQUOTE&/'; $repl[] = '\''; $patt[] = '/&SCREENDBQUOTE&/'; $repl[] = '"'; $patt[] = '/&SCREENDBSLASH&/'; $repl[] = '//'; $patt[] = '/&SCREENEDEQUAL&/'; $repl[] = '='; if ($is_unicode) { $patt = sk_pattern2unicode($patt); } $ret = array(); $str = sk_unix_linefeeds($str, $is_unicode); $tmppat = '/(?<=\\=)\\s*\'\'/'; if ($is_unicode) { $tmppat = sk_pattern2unicode($tmppat); } $str = preg_replace($tmppat, '$1', $str); $tmppat = '/(?<!\\x5C)\'(.*[^\\x5C])\'/Us'; if ($is_unicode) { $tmppat = sk_pattern2unicode($tmppat); $str = preg_replace_callback($tmppat, create_function('$in', 'return sl_screenspecial($in[1], true);'), $str); } else { $str = preg_replace_callback($tmppat, create_function('$in', 'return sl_screenspecial($in[1], false);'), $str); } $str = sk_clean_config($str, $is_unicode); $strings = explode("\n", $str); foreach ($strings as $val) { $pair = explode('=', $val); if (isset($pair[0])) { $ret[trim($pair[0])][] = isset($pair[1]) ? preg_replace($patt, $repl, trim($pair[1])) : true; } } return $ret; }