Skip to content

brycegough/PHP-CSS-Functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

CSS Functions

Standalone PHP Class

Apply user defined functions to a block of CSS code - or any string for that matter..

Example

Input

.some-param {
    margin: @@my_function();
}

@media(max-width: @@my_function(4)) {
    @@another_function(123, 456)
}

PHP

include(__DIR__ . '/CSSFunctions.php');

$compiler = new CSSFunctions( $input, [

    'my_function' => function($args) {
        return ( $args[0] ?? '0' ) . 'px';
    },

    'another_function' => function($args) {
        return "/* Another function: " . implode('|', $args) . " */";
    }

] );

echo '<pre>' . $compiler->compile() . '</pre>';

Output

.some-param {
    margin: 0px;
}

@media(max-width: 4px) {
    /* Another function: 123|456 */
}

About

Apply user defined functions to a block of CSS code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages