<?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 {
foreach($this->attr as $try) {
if ($try->Name() === $name) {
return $this->attr[$name];
}
}
return new Attribute("");
}
}
public function SetAttr($name, $value) {
$exist = false;
foreach($this->attr as $try) {
if ($try->Name() === $name) {
$try->Value($value);
$exist = true;
}
}
if (!$exist) {
array_push($this->attr, new Attr($name, $value));
}
}
public function AttrFromString($string) {
$items = explode(" ", $string);
$newlist = array();
foreach($items as $yes) {
if (strpos($yes, "=")!==false) {
$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])-1);
}
array_push($newlist, new Attribute($as[0], $as[1]));
}
array_merge($this->attr, $newlist);
}
public function RemoveAttr($name = null) {
if ($name === null) {
$this->attr = array();
}
else {
for($i = 0; $i < count($this->attr); $i++) {
if ($this->attr[$i]->Name() === $name) {
unset($this->attr[$i]);
}
}
}
}
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 ). "'")));
}
}
$a = new Element("a");
$a->AddAttr(new Attribute("href", "http://twitter.nl"));
$a->AddAttr(new Attribute("target", "_blank"));
$span = new Element("span");
$span->AddAttr(new Attribute("style", array("color" => "orange","background-color" => "green")));
$span->Value("doei"); //Ads Doei in Span
$span->AttrFromString("rel='none'"); //Adds Rel to None
$img = new Element("img", true); //Makes Img Element
$img->AddAttr(new Attribute("src", "https://www.google.nl/images/srpr/logo4w.png")); //Adds SRC
$a->RemoveAttr("href"); //Removes Href Attribute
$a->Value($span . NewLine. "hello world" .NewLine . $img); //Changes Inner Html of the A
echo $a;
- Output for 8.4.1 - 8.4.6
- Fatal error: Cannot redeclare class Attribute in /in/uaQCm on line 83
Process exited with code 255. - Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.32, 8.2.0 - 8.2.28, 8.3.0 - 8.3.20
- Fatal error: Cannot declare class Attribute, because the name is already in use in /in/uaQCm on line 83
Process exited with code 255. - Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
- <a target='_blank'><span style='color:orange;background-color:green;'>doei</span><br />hello world<br /><img src='https://www.google.nl/images/srpr/logo4w.png'/></a>
preferences:
151.89 ms | 411 KiB | 5 Q