src/CssConverter.php
public function convertBackground($css, &$value)
    {
        // is there a image ?
        $text = '/url\(([^)]*)\)/isU';
        if (preg_match($text, $css, $match)) {
            // get the image
            $value['image'] = $this->convertBackgroundImage($match[0]);

            // remove if from the css properties
            $css = preg_replace($text, '', $css);
            $css = preg_replace('/[\s]+/', ' ', $css);
        }

        // protect some spaces
        $css = preg_replace('/,[\s]+/', ',', $css);

        // explode the values
        $css = explode(' ', $css);

        // background position to parse
        $pos = '';

        // foreach value
        foreach ($css as $val) {
            // try to parse the value as a color
            $ok = false;
            $color = $this->convertToColor($val, $ok);

            // if ok => it is a color
            if ($ok) {
                $value['color'] = $color;
                // else if transparent => no coloàr
            } elseif ($val === 'transparent') {
                $value['color'] = null;
                // else
            } else {
                // try to parse the value as a repeat
                $repeat = $this->convertBackgroundRepeat($val);

                // if ok => it is repeat
                if ($repeat) {
                    $value['repeat'] = $repeat;
                    // else => it could only be a position
                } else {
                    $pos.= ($pos ? ' ' : '').$val;
                }
            }
        }

        // if we have a position to parse
        if ($pos) {
            // try to read it
            $pos = $this->convertBackgroundPosition($pos, $ok);
            if ($ok) {
                $value['position'] = $pos;
            }
        }
    }
public function convertBackground($css, &$value)
    {
        // is there a image ?
        $text = '/url\(([^)]*)\)/isU';
        if (preg_match($text, $css, $match)) {
            // get the image
            $value['image'] = $this->convertBackgroundImage($match[0]);

            // remove if from the css properties
            $css = preg_replace($text, '', $css);
            $css = preg_replace('/[\s]+/', ' ', $css);
        }

        // protect some spaces
        $css = preg_replace('/,[\s]+/', ',', $css);

        // explode the values
        $css = explode(' ', $css);

        // background position to parse
        $pos = '';

        // foreach value
        foreach ($css as $val) {
            // try to parse the value as a color
            $ok = false;
            $color = $this->convertToColor($val, $ok);

            // if ok => it is a color
            if ($ok) {
                $value['color'] = $color;
                // else if transparent => no coloàr
            } elseif ($val === 'transparent') {
                $value['color'] = null;
                // else
            } else {
                // try to parse the value as a repeat
                $repeat = $this->convertBackgroundRepeat($val);

                // if ok => it is repeat
                if ($repeat) {
                    $value['repeat'] = $repeat;
                    // else => it could only be a position
                } else {
                    $pos.= ($pos ? ' ' : '').$val;
                }
            }
        }

        // if we have a position to parse
        if ($pos) {
            // try to read it
            $pos = $this->convertBackgroundPosition($pos, $ok);
            if ($ok) {
                $value['position'] = $pos;
            }
        }
    }
public function convertBackground ( $ css , & $ value ) { // is there a image ? $ text = '/url\(([^)]*)\)/isU' ; if ( preg_match ( $ text , $ css , $ match ) ) { // get the image $ value [ 'image' ] = $ this -> convertBackgroundImage ( $ match [ 0 ] ) ; // remove if from the css properties $ css = preg_replace ( $ text , '' , $ css ) ; $ css = preg_replace ( '/[\s]+/' , ' ' , $ css ) ; } // protect some spaces $ css = preg_replace ( '/,[\s]+/' , ',' , $ css ) ; // explode the values $ css = explode ( ' ' , $ css ) ; // background position to parse $ pos = '' ; // foreach value foreach ( $ css as $ val ) { // try to parse the value as a color $ ok = false ; $ color = $ this -> convertToColor ( $ val , $ ok ) ; // if ok => it is a color if ( $ ok ) { $ value [ 'color' ] = $ color ; // else if transparent => no coloàr } elseif ( $ val === 'transparent' ) { $ value [ 'color' ] = null ; // else } else { // try to parse the value as a repeat $ repeat = $ this -> convertBackgroundRepeat ( $ val ) ; // if ok => it is repeat if ( $ repeat ) { $ value [ 'repeat' ] = $ repeat ; // else => it could only be a position } else { $ pos .= ( $ pos ? ' ' : '' ) . $ val ; } } } // if we have a position to parse if ( $ pos ) { // try to read it $ pos = $ this -> convertBackgroundPosition ( $ pos , $ ok ) ; if ( $ ok ) { $ value [ 'position' ] = $ pos ; } } }
Analyse a background

@param  string $css css background properties
@param  &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties)

@return void
Analyse a background