lundi 8 juin 2020

Extract all the .classes from different .css files and randomize the values in php

I have 3 files storing a few classes for my website buttons:

colours.css / .blue .red .black .white .green .yellow
sizes.css / .small .medium .big .superbig
effects.css / .slide-in-elliptic-bottom-fwd .bounce-in-fwd .slide-in-blurred-top

I'd like to set my config file to read these files and extract all the classes (.whatever) to combine and randomize them getting 1 value from each file and do the output like this:

blue small slide-in-blurred-top or black medium bounce-in-fwd

It doesn't matter the order while I can call the function on the easiest/lightest way after like this

a class="button <?php echo $mixclasses ?>"

XX times on each page of my site.

At the moment I have:

function getRandomLines() { 

$textfile  =  'animista.css';
        if(file_exists($textfile)){ 
            $featurefile = file($textfile);             
        } else {
            $featurefile = array("Error, no file found!");
        }
    return $featurefile;
}
function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}

$features = getRandomLines();
echo ('<h2 class="text-flicker-in-glow">Classes</h2>');
foreach($features as $feature => $value) {  
    $valuereal = get_string_between($value, '.', ' {');
    if ((strpos($value, '.') !== false) && (strlen($value) > 4) && (strpos($value, '-') !== false) && (1 === preg_match('~[0-9]~', $value)) == false)  {        
    echo ' '.$valuereal.' <br/>';       
    }   
}

I'd like to even make an array with the files and mix dynamically the extracted values as per explanation before. Thanks




Aucun commentaire:

Enregistrer un commentaire