public static function mergeStyles($a, $b)
    {
        /*
         * Cut the styles at the ; symbols
         */
        $a = explode(';', $a);

        /*
         * Will contain all style keys and the indexes of them in $a.
         */
        $amap = array();

        /*
         * Getter for the style key.
         */
        $gk = function ($s) {
            return trim(substr($s, 0, strpos($s, ':')));
        };

        /*
         * Cleanup $a and build the map.
         */
        foreach ($a as $k => $v) {
            if (trim($v) == '') {
                unset($a[$k]);
                continue;
            }
            $a[$k] = trim($v);
            $amap[$gk($v)] = $k;
        }

        /*
         * Merge $b
         */
        foreach (explode(';', $b) as $st) {
            if (trim($st) == '') {
                continue;
            }

            /*
             * If the current key is set in the map.
             * remove it from $a
             */
            if (isset($amap[$gk($st)])) {
                unset($a[$amap[$gk($st)]]);
            }
            $a[] = trim($st);
        }

        /*
         * sort, minimize and return.
         */
        sort($a);

        return str_replace(array(': ', ': '), ':', implode(';', $a)).';';
    }
public static function mergeStyles($a, $b)
    {
        /*
         * Cut the styles at the ; symbols
         */
        $a = explode(';', $a);

        /*
         * Will contain all style keys and the indexes of them in $a.
         */
        $amap = array();

        /*
         * Getter for the style key.
         */
        $gk = function ($s) {
            return trim(substr($s, 0, strpos($s, ':')));
        };

        /*
         * Cleanup $a and build the map.
         */
        foreach ($a as $k => $v) {
            if (trim($v) == '') {
                unset($a[$k]);
                continue;
            }
            $a[$k] = trim($v);
            $amap[$gk($v)] = $k;
        }

        /*
         * Merge $b
         */
        foreach (explode(';', $b) as $st) {
            if (trim($st) == '') {
                continue;
            }

            /*
             * If the current key is set in the map.
             * remove it from $a
             */
            if (isset($amap[$gk($st)])) {
                unset($a[$amap[$gk($st)]]);
            }
            $a[] = trim($st);
        }

        /*
         * sort, minimize and return.
         */
        sort($a);

        return str_replace(array(': ', ': '), ':', implode(';', $a)).';';
    }
public static function mergeStyles ( $ a , $ b ) { /*
         * Cut the styles at the ; symbols
         */ $ a = explode ( ';' , $ a ) ; /*
         * Will contain all style keys and the indexes of them in $a.
         */ $ amap = array ( ) ; /*
         * Getter for the style key.
         */ $ gk = function ( $ s ) { return trim ( substr ( $ s , 0 , strpos ( $ s , ':' ) ) ) ; } ; /*
         * Cleanup $a and build the map.
         */ foreach ( $ a as $ k => $ v ) { if ( trim ( $ v ) == '' ) { unset ( $ a [ $ k ] ) ; continue ; } $ a [ $ k ] = trim ( $ v ) ; $ amap [ $ gk ( $ v ) ] = $ k ; } /*
         * Merge $b
         */ foreach ( explode ( ';' , $ b ) as $ st ) { if ( trim ( $ st ) == '' ) { continue ; } /*
             * If the current key is set in the map.
             * remove it from $a
             */ if ( isset ( $ amap [ $ gk ( $ st ) ] ) ) { unset ( $ a [ $ amap [ $ gk ( $ st ) ] ] ) ; } $ a [ ] = trim ( $ st ) ; } /*
         * sort, minimize and return.
         */ sort ( $ a ) ; return str_replace ( array ( ': ' , ': ' ) , ':' , implode ( ';' , $ a ) ) . ';' ; }
Merges two strings containing styles.

@param string $a style A
@param string $b style B

@return string style A + style B
Merges two strings containing styles .