public static function html_selector2struc($sel)
    {
        $sc  = '#.:';
        $n   = null;
        $a   = array();
        $def = array('n' => $n, 'i' => $n, 'c' => $a, 'p' => $a);
        $sel = rtrim(trim(preg_replace('/\\s*(>|,)\\s*/', '$1', $sel), " \t\n\r,>"), $sc);
        $sel = explode(',', $sel);
        foreach ($sel as &$a) {
            $a = preg_split('|\\s+|', $a);
            foreach ($a as &$b) {
                $b = explode('>', $b);
                foreach ($b as &$c) {
                    $d = $def;
                    $l = strlen($c);
                    $j = strcspn($c, $sc, 0, $l);
                    if ($j) {
                        $d['n'] = substr($c, 0, $j);
                    }

                    $i = $j;
                    while ($i < $l) {
                        $k = $c[$i++];
                        $j = strcspn($c, $sc, $i, $l);
                        if ($j) {
                            $e = substr($c, $i, $j);
                            switch ($k) {
                                case '.':$d['c'][] = $e;
                                    break;
                                case '#':$d['i'] = $e;
                                    break;
                                case ':':$d['p'][] = self::html_normal_pseudoClass($e);
                                    break;
                            }
                            $i += $j;
                        }
                    }
                    if (empty($d['c'])) {
                        $d['c'] = $n;
                    }

                    if (empty($d['p'])) {
                        $d['p'] = $n;
                    }

                    $c = $d;
                }
            }
        }
        return $sel;
    }
public static function html_selector2struc($sel)
    {
        $sc  = '#.:';
        $n   = null;
        $a   = array();
        $def = array('n' => $n, 'i' => $n, 'c' => $a, 'p' => $a);
        $sel = rtrim(trim(preg_replace('/\\s*(>|,)\\s*/', '$1', $sel), " \t\n\r,>"), $sc);
        $sel = explode(',', $sel);
        foreach ($sel as &$a) {
            $a = preg_split('|\\s+|', $a);
            foreach ($a as &$b) {
                $b = explode('>', $b);
                foreach ($b as &$c) {
                    $d = $def;
                    $l = strlen($c);
                    $j = strcspn($c, $sc, 0, $l);
                    if ($j) {
                        $d['n'] = substr($c, 0, $j);
                    }

                    $i = $j;
                    while ($i < $l) {
                        $k = $c[$i++];
                        $j = strcspn($c, $sc, $i, $l);
                        if ($j) {
                            $e = substr($c, $i, $j);
                            switch ($k) {
                                case '.':$d['c'][] = $e;
                                    break;
                                case '#':$d['i'] = $e;
                                    break;
                                case ':':$d['p'][] = self::html_normal_pseudoClass($e);
                                    break;
                            }
                            $i += $j;
                        }
                    }
                    if (empty($d['c'])) {
                        $d['c'] = $n;
                    }

                    if (empty($d['p'])) {
                        $d['p'] = $n;
                    }

                    $c = $d;
                }
            }
        }
        return $sel;
    }
public static function html_selector2struc ( $ sel ) { $ sc = '#.:' ; $ n = null ; $ a = array ( ) ; $ def = array ( 'n' => $ n , 'i' => $ n , 'c' => $ a , 'p' => $ a ) ; $ sel = rtrim ( trim ( preg_replace ( '/\\s*(>|,)\\s*/' , '$1' , $ sel ) , " \t\n\r,>" ) , $ sc ) ; $ sel = explode ( ',' , $ sel ) ; foreach ( $ sel as & $ a ) { $ a = preg_split ( '|\\s+|' , $ a ) ; foreach ( $ a as & $ b ) { $ b = explode ( '>' , $ b ) ; foreach ( $ b as & $ c ) { $ d = $ def ; $ l = strlen ( $ c ) ; $ j = strcspn ( $ c , $ sc , 0 , $ l ) ; if ( $ j ) { $ d [ 'n' ] = substr ( $ c , 0 , $ j ) ; } $ i = $ j ; while ( $ i < $ l ) { $ k = $ c [ $ i ++ ] ; $ j = strcspn ( $ c , $ sc , $ i , $ l ) ; if ( $ j ) { $ e = substr ( $ c , $ i , $ j ) ; switch ( $ k ) { case '.' : $ d [ 'c' ] [ ] = $ e ; break ; case '#' : $ d [ 'i' ] = $ e ; break ; case ':' : $ d [ 'p' ] [ ] = self :: html_normal_pseudoClass ( $ e ) ; break ; } $ i += $ j ; } } if ( empty ( $ d [ 'c' ] ) ) { $ d [ 'c' ] = $ n ; } if ( empty ( $ d [ 'p' ] ) ) { $ d [ 'p' ] = $ n ; } $ c = $ d ; } } } return $ sel ; }
Parse a selector string into an array structure.

tn1#id1 .cl1.cl2:first tn2:5 , tn3.cl3 tn4#id2:eq(-1) > tn5:last-child > tn6:lt(3)
-->
[
[
[{ n: "tn1", i: "id1", c: [],            p: []  }],
[{ n: NULL,  i: NULL,  c: ["cl1","cl2"], p: [0] }],
[{ n: "tn2", i: NULL,  c: [],            p: [5] }]
]
, [
[{ n: "tn3", i: NULL, c: ["cl3"], p: [] }],
[
{ n: "tn4", i: "id2", c: [], p: [-1]   },
{ n: "tn5", i: NULL , c: [], p: [-1]   },
{ n: "tn6", i: NULL , c: [], p: ["<3"] }
]
]
]

@internal
@return array
Parse a selector string into an array structure .