PHP code example of irmmr / rtlcss

1. Go to this page and download the library: Download irmmr/rtlcss library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

irmmr / rtlcss example snippets


// it's very simple and I know this
$css_code = "div { float: left; }";

// parse css code
$css_parser = new Parser($css_content);

try {
    $css_tree = $css_parser->parse();
} catch (SourceException $e) {
    // Error occ
    return;
}

// create rtlcss parser
$rtlcss = new RTLParser($css_tree);

// parsing css rules and properties
$rtlcss->flip();

// get parsed css code ==> div {float: right;}
echo $css_tree->render();

// using rgb(0 0 0 / 20%)
$css_code = "
div {
    float: left;
    box-shadow: 2px 2px 2px 1px rgb(0 0 0 / 20%);
}
";
...

// create rtlcss parser
$rtlcss = new RTLParser($css_tree);

// parsing css rules and properties
$rtlcss->flip();

// using rgb(0 0 0 / 20%)
$css_code = "
div {
    float: left;
    box-shadow: 2px 2px 2px 1px rgb(0 0 0 / 20%);
}
";

// rtl encoder
$rtl_encode = new Encode($css_code);

// change css value
$css_code = $rtl_encode->encode();

// parse css code
$css_parser = new Parser($css_content);

try {
    $css_tree = $css_parser->parse();
} catch (SourceException $e) {
    // Error occ
    return;
}

// create rtlcss parser
$rtlcss = new RTLParser($css_tree);

// parsing css rules and properties
$rtlcss->flip();

// get rendered and update encoded
$rendered = $css_tree->render();
$rtl_encode->setEncoded($rendered);

// get parsed css code
echo $rtl_encode->decode();