public static function fromString( $string )
  {
    if( preg_match( '#(\s+)?([^:]+):([^!;]+)([^;]+)?#', trim( $string, "\n\r" ), $matches ) )
    {
      $rule = new self();
      $rule
          ->setRaw($string)
          ->setProperty( ( !empty( $matches[ 2 ] ) ) ? trim( $matches[ 2 ] ) : null )
          ->setValue( ( !empty( $matches[ 3 ] ) ) ? trim( $matches[ 3 ] ) : null )
          ->setBang( ( !empty( $matches[ 4 ] ) ) ? trim( $matches[ 4 ] ) : null )
          ->setIndent( ( isset( $matches[ 1 ] ) ) ? strlen( $matches[ 1 ] ) : 0 )
      ;

      // Replace Property in Template
      $pattern  = "#(" . preg_quote( $rule->getProperty(), "#" ) . "([\s:]+))#";

      $template = preg_replace( $pattern, "%s$2", $matches[ 0 ] . ';' );

      // Replace Value in Template
      $pattern = "#(:([\s]+))" . preg_quote( $rule->getValue(), "#" ) . "#";
      $template = preg_replace(  $pattern, "$1%s", $template );

      // Replace Bang in Template
      $pattern  = "#([^!]+)" . preg_quote($rule->getBang(), "#") . ";#";
      $template = preg_replace( $pattern, "$1%s;", $template );

      return $rule->setTemplate( $template );
    }

    return null;
  }
public static function fromString( $string )
  {
    if( preg_match( '#(\s+)?([^:]+):([^!;]+)([^;]+)?#', trim( $string, "\n\r" ), $matches ) )
    {
      $rule = new self();
      $rule
          ->setRaw($string)
          ->setProperty( ( !empty( $matches[ 2 ] ) ) ? trim( $matches[ 2 ] ) : null )
          ->setValue( ( !empty( $matches[ 3 ] ) ) ? trim( $matches[ 3 ] ) : null )
          ->setBang( ( !empty( $matches[ 4 ] ) ) ? trim( $matches[ 4 ] ) : null )
          ->setIndent( ( isset( $matches[ 1 ] ) ) ? strlen( $matches[ 1 ] ) : 0 )
      ;

      // Replace Property in Template
      $pattern  = "#(" . preg_quote( $rule->getProperty(), "#" ) . "([\s:]+))#";

      $template = preg_replace( $pattern, "%s$2", $matches[ 0 ] . ';' );

      // Replace Value in Template
      $pattern = "#(:([\s]+))" . preg_quote( $rule->getValue(), "#" ) . "#";
      $template = preg_replace(  $pattern, "$1%s", $template );

      // Replace Bang in Template
      $pattern  = "#([^!]+)" . preg_quote($rule->getBang(), "#") . ";#";
      $template = preg_replace( $pattern, "$1%s;", $template );

      return $rule->setTemplate( $template );
    }

    return null;
  }
public static function fromString ( $ string ) { if ( preg_match ( '#(\s+)?([^:]+):([^!;]+)([^;]+)?#' , trim ( $ string , "\n\r" ) , $ matches ) ) { $ rule = new self ( ) ; $ rule -> setRaw ( $ string ) -> setProperty ( ( ! empty ( $ matches [ 2 ] ) ) ? trim ( $ matches [ 2 ] ) : null ) -> setValue ( ( ! empty ( $ matches [ 3 ] ) ) ? trim ( $ matches [ 3 ] ) : null ) -> setBang ( ( ! empty ( $ matches [ 4 ] ) ) ? trim ( $ matches [ 4 ] ) : null ) -> setIndent ( ( isset ( $ matches [ 1 ] ) ) ? strlen ( $ matches [ 1 ] ) : 0 ) ; // Replace Property in Template $ pattern = "#(" . preg_quote ( $ rule -> getProperty ( ) , "#" ) . "([\s:]+))#" ; $ template = preg_replace ( $ pattern , "%s$2" , $ matches [ 0 ] . ';' ) ; // Replace Value in Template $ pattern = "#(:([\s]+))" . preg_quote ( $ rule -> getValue ( ) , "#" ) . "#" ; $ template = preg_replace ( $ pattern , "$1%s" , $ template ) ; // Replace Bang in Template $ pattern = "#([^!]+)" . preg_quote ( $ rule -> getBang ( ) , "#" ) . ";#" ; $ template = preg_replace ( $ pattern , "$1%s;" , $ template ) ; return $ rule -> setTemplate ( $ template ) ; } return null ; }
Create a CssRule object from an existing CSS string.

@param string $string

@return null|CssRule
Create a CssRule object from an existing CSS string .