Tag Klasse
Mit dieser Klasse kann man via RegEx einen bestimmten Code Tag anlegen und Attribute beliebig verändern
|
Script: |
<?php
class tag {
var
$tag, // The type of tag (A, TITLE, etc)
$content, // the contents of the tag
$attribute; // an associative array of the attributes and their values
function tag($tag) {
preg_match('/<(.)\s*([^>]*)>(.*)<\/\1>/i',$tag,$match);
$this->content = $match[3];
$this->tag = $match[1];
$tmp = trim($match[2]);
if (strlen($tmp)){
$tmp = preg_replace('/\s*=\s*/','=',$tmp);
$tmpArray = explode(" ",$tmp);
foreach($tmpArray as $nv) {
list($name, $value) = explode("=",$nv);
$value = (is_null($value)) ? null : preg_replace('/\s*\"*\'*([^\'^\">]*)\"*\'*/',"$1",$value);
$this->attribute[$name] = $value;
}
}
}
function write() {
if (is_array($this->attribute)) {
foreach ($this->attribute as $key=>$value) {
$tmp = $key;
if (!is_null($value)) $tmp .= "=\"$value\"";
$attributes[] = $tmp;
}
$attrString = join($attributes, " ");
}
$return = "<{$this->tag}";
if (strlen($attrString)) $return .= " ".$attrString;
$return .= ">{$this->content}</{$this->tag}>";
return $return;
}
}
?>
|
|