L’esperienza insegna 46….(livelli fib s&pmib) Costruire un carrello e-commerce con jquery e codeigniter!




Dic 18

Questo bellissimo script permette di leggere file CCS memorizzando i parametri di formattazione all’interno di una sessione, questi valori potranno essere recuperati tramite un ciclo.

 
//if no style loaded load
$lines = file("style_sheet.css");
foreach ($lines as $line_num => $line) {
 
$cssstyles .= trim($line);
}
//using strtok we remove the brackets around the css styles
 
$tok = strtok($cssstyles, "{}");
//For example, the style: p{color:#000000;} now looks like this p color:#000000;
 
//crete another array in which we will store tokenized string
$sarray = array();
//set counter
$spos = 0;
//with this while loop we are basically separating selectors from styles and store those values in the $sarray
while ($tok !== false) {
 
$sarray[$spos] = $tok;
$spos++;
$tok = strtok("{}");
}
//if you run print_r($sarray); the result would be:
//Array ( [0] => p [1] => color:#000000;
// [2] => h1 [3] => font-size:18px;color:#666666;
// [4] => table [5] => width:100%; border:1px solid #000000;)
//As you can see all selectors are stored in odd number positions of the array and styles in even.
//That is an important piece of information that we will use to to go through $sarray and store
 
//all selectors in one array and styles in the other.
 
// To start we need to get the size of $sarray
$size = count($sarray);
 
//create selectors and styles arrays
$selectors = array();
$sstyles = array();
 
//set counters
$npos = 0;
$sstl = 0;
 
//a simple for loop with modulus operator will help us separate styles from selectors.
for($i = 0; $i< $size; $i++){
if ($i % 2 == 0) {
$selectors[$npos] = $sarray[$i];
$npos++;
}else{
$sstyles[$sstl] = $sarray[$i];
$sstl++;
}
}
 
//all that’s left is store names and styles in a session for us to use
$_SESSION[’style_names’] = $selectors;
$_SESSION[’style_styles’] = $sstyles;
//now if you run print_r($selectors); and print_r($sstyles);
 
//you’ll notice that you can access individual selectors and it’s styles using array keys
//In this example $selectors[0] value is "p" and $sstyles[0] value is "p" property/value pair-color:#000000;
 

fonte: www.sastgroup.com » Vai al post originale





Scrivi un commento