Example #1
0
/**
 * 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;
}
Example #2
0
function sk_parse_config_str($str)
{
    $patt[] = '/&SCREENEDSPACE&/';
    $repl[] = ' ';
    $patt[] = '/&SCREENEDLFEED&/';
    $repl[] = "\n";
    $patt[] = '/&SCREENSNQUOTE&/';
    $repl[] = '\'';
    $patt[] = '/&SCREENDBQUOTE&/';
    $repl[] = '"';
    $patt[] = '/&SCREENDBSLASH&/';
    $repl[] = '//';
    $patt[] = '/&SCREENEDEQUAL&/';
    $repl[] = '=';
    $ret = array();
    $str = sk_unix_linefeeds($str);
    $str = preg_replace('/(?<=\\=)\\s*\'\'/', '$1', $str);
    //	TODO: rewrite following with = and \n
    $str = preg_replace('/(?<!\\x5C)\'(.*[^\\x5C])\'/Ues', 'sl_screenspecial(\'$1\')', $str);
    //	$str = preg_replace('/"([^"]*)"/Ues', 'sl_screenspecial(\'$1\')', $str);
    $str = sk_clean_config($str);
    $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;
}