@ 2013-05-30T11:03:26Z <?php
class Element {
private $single, $tag, $value, $attr=array();
public function __construct($tag, $single = false) {
$this->tag = $tag;
$this->single = $single;
}
public function Value($value) {
$this->value = $value;
}
public function AddAttr($attr, $list = false) {
if ($list) {
array_merge($this->attr, $list);
}
else {
array_push($this->attr, $attr);
}
}
public function GetAttr($name = null) {
if ($i === null) {
return $this->attr;
}
else {
return $this->attr[$name];
}
}
public function AttrFromString($string) {
$items = explode(" ", $string);
$newlist = array();
foreach($items as $yes) {
if (strpos($yes, "=")) {
$as = explode('=', $yes);
}
else {
$as[0] = $yes;
$as[1] = "";
}
if (substr($as[1], 0,1) == "'" || substr($as[1], 0,1) == '"') {
$as[1] = substr($as[1],1,strlen($as)-1);
}
array_push($newlist, new Attribute($as[0], $as[1]));
}
array_merge($this->attr, $newlist);
}
public function SetAttr($name, $value) {
$this->attr[$name] = $value;
}
public function RemoveAttr($name = null) {
if ($name === null) {
$attr = array();
}
else {
unset($attr[$name]);
}
}
public function __toString() {
return "<" . $this->tag . " " . implode(" ",$this->attr) . ($this->single ? (!empty($this->value) ? "value='" . $this->value ."'" : "" ). "/>" : '>' . $this->value . '</'.$this->tag.'>');
}
}
define(NewLine, "<br />");
define(DocType, '<!DOCTYPE html>');
class Attribute {
private $name, $value;
public function __construct($name, $value = "") {
$this->name = $name;
$this->value = $value;
}
public function Name($name = null) {
if ($name === null) {
return $this->name;
}
else {
$this->name = $name;
}
}
public function Value($value = null) {
if ($value === null) {
return $this->value;
}
else {
$this->value = $value;
}
}
public function __toString() {
if (is_array($this->value)) {
$code = "";
foreach ($this->value as $key => $value) {
$code .= $key . ":" . $value . ';';
}
}
return ($this->value === true ? $this->name : ($this->value === false ? "" : ($this->value === "" ? $this->name : $this->name . "='".(is_array($this->value) ? $code : $this->value ). "'")));
}
}
$element = new Element("a");
$element->AddAttr(new Attribute("href", "http://google.nl"));
$element->AddAttr(new Attribute("target", "_blank"));
$element2 = new Element("span");
$element2->AddAttr(new Attribute("style", array("color" => "orange","background-color" => "green")));
$element2->Value("doei");
$element2->AttrFromString("required");
$element3 = new Element("img", true);
$element3->AddAttr(new Attribute("src", "https://si0.twimg.com/profile_images/3439429669/c2c9d02095be44d026d358e0a39bced0_normal.jpeg"));
$element->Value($element2 . NewLine. "hoi" .NewLine . $element3);
echo $element;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for git.master , git.master_jit , rfc.property-hooks Fatal error: Uncaught Error: Undefined constant "NewLine" in /in/vPVEv:61
Stack trace:
#0 {main}
thrown in /in/vPVEv on line 61
Process exited with code 255 . This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches Archived branches Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:dark mode live preview
36.27 ms | 401 KiB | 8 Q