If you build a website, where the user should have the possibility to customize the appearence - then this is for you.
Combined with some
৺MySQL Readouts, this class can create a complete Stylesheet.
class DynStyle{
var $values;
var $obj;
function DynStyle($obj){
$this->obj = $obj;
}
function AddAttribute($key, $value = ""){
if ($value) $this->values[] = "$key: $value";
else $this->values[] = $key;
}
function dump(){
echo "$this->obj { ".implode("; ", $this->values)." }<br>"; }
}
Usage:
$body = new DynStyle("body");
//Possibility One
$body->AddAttribute("margin","0px");
//Possibility Two
$body->AddAttribute("padding: 0px");
//Possibility Three
$body->AddAttribute("background-color: red; color:blue");
$body->dump();
This dumps a entry looking like that:
body { margin: 0px; padding: 0px; background-color: red; color:blue }