Selection Box 1

Sample Code:

include 'xTags.php';

$xTag = new xTags();

echo '<h3>Selection Box 1</h3>';
$op = array('opt1'=>'Option 1','opt2'=>'Option 2');
foreach($op as $v=>$t){
$select = ($_POST['selectbox'] == $v) ? ',selected:selected' : '';
$opt .= $xTag->tag('option',$t,'value:'.$v.$select);
}
$list = $xTag->xlist('txt:'.$opt.',x:select,id:selectbox,name:selectbox');
$art = $xTag->tag('article',$list,'id:mainWin');
echo $art;

Selection Box 2

Sample Code:

echo '<h3>Selection Box 2</h3>';
$opt = $xTag->tag('option','Option One','value:1,selected:selected',0);
$list = $xTag->xlist('txt:'.$opt.',x:select,id:selectbox,name:selectbox');
$art = $xTag->tag('article',$list,'id:mainWin');
echo $art;

Link Tag

Revolution Visual Arts

Sample Code:

echo '<h3>Link Tag</h3>';
$tag = $xTag->tag('a','Revolution Visual Arts','href:http..//www.revolutionvisualarts.com,target:_blank');
echo $tag;

Source Code:

<?php
class xTags{
	//Author: Rafael Vila
   /*
   License:
   This work is licensed under the Creative Commons Attribution 3.0 Unported License.
   To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/
   or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. 
   */
   public $str;
   const s1 = ',';
   const s2 = ':';
   const s3 = '-';
   const s4 = '&';
   
   function tag($tagName, $content, $attList, $sclose = 0){
   	$this->str = $this->gTag($tagName, $content, $attList, $sclose);
   	return $this->str;
   }
   
   function gTag($nm,$ct,$att,$sclt){
   	$aList = explode(self::s1,$att);
   	foreach($aList as $al){
   		$at = explode(self::s2,$al);
   		$a = $at[0];
   		$e = str_replace('..',':',str_replace('~',',',$at[1]));
   		if(!empty($at[0])){
   		$jn[] = $a.'="'.$e.'"';
   		}
   	}
   	if(isset($jn)){
   		$list = join(' ',$jn);
   		$ls = ' '.$list;
   	}
  	 $r = ($sclt == 0) ? '<'.$nm.$ls.'>'.$ct.'</'.$nm.'>' : '<'.$nm.$ls.' value="'.$ct.'" />';
   	return $r;
   }
   
   function createVariables(){
   	$str = $this->str;
   	$str = trim($str);
   	$farr = explode(self::s1,$str);
   	if(is_array($farr)){
   		foreach($farr as $fa){
   			$fa = trim($fa);
   			if(strpos($fa,self::s2)){
   				#for debug purposes
   				#echo '<span style="color:yellow;">'.$fa.'</span><br />';
   				$n = explode(':',$fa);
   				$n[0] = trim($n[0]);
   				$n[1] = trim($n[1]);
   				$r[$n[0]] = $n[1];
   			}
   		}
   	}
   
   	return $r;
   }
   
   function dynAt($att,$exec){
   	$r = ' '.$att.'="'.$st.'" ';
   	return $r;
   }
   
   function h($txt,$n,$att=""){
   	$t = 'h'.$n;
   	return $this->tag($t,$txt,$att);
   }
   
   function tbl($txt,$att="",$b=0,$s=0,$p=0){
   	$cmm = (!empty($att)) ? ',' : '';
   	$stdAtt = 'border:'.$b.',cellspacing:'.$s.',cellpadding:'.$p.$cmm;
   	$att = $stdAtt.$att;
   	return $this->tag('table',$txt,$att);
   }
   
   function frm($txt,$att="",$a="",$m="",$e=""){
   	$act = (!empty($a)) ? 'action:'.$a : '';
   	$met = (!empty($m)) ? 'method:'.$m : '';
   	$enc = (!empty($e)) ? 'enctype:'.$e : '';
   	$aarr = array('act','met','enc','att');
   	foreach ($aarr as $ar){
   		if(!empty(${$ar})){
   			$arr[] = ${$ar};
   		}
   	}
   	$att = (is_array($arr)) ? join(',',$arr) : $att;
   	return $this->tag('form',$txt,$att);
   }
   
   function xlist($str){
   	$this->str = $str;
   	$arr = $this->createVariables();
   	if(is_array($arr)){
   		foreach($arr as $k=>$v){
   			if($k == 'tit' || $k == 'txt' || $k=='lst' || $k=='x'){
   				${$k} = $v;
   			} else {
   				$xatt[] = $k.':'.$v;
   			}
   			#for debug purposes
   			#echo '<span style="color:white;">'.$k.' value is '.${$k}.'</span><br />';
   		}
   		if(isset($lst)){
   			$list = explode(self::s3,$lst);
   		}
   		//need to be format to create array. 
   		//sample " 'First Object [label]&[class]&[js element(optional)]&[js function(optional)]-Second Object [label]-Third Object [label],[class]' "
   		//as many as you like using dash [-] as the separator no spaces.
   
   		if(is_array($list)){
   			$i = 0;
   			foreach($list as $l){
   				$lid = (!empty($id))? $id.$i : '';
   				$lex = explode(self::s4,$l);
   				$lat .= 'id:'.$lid.',';
   				$lat .= (isset($lex['1'])) ? 'class:'.$lex['1'].',' : '';
   				$lat .= (isset($lex['2'])) ? $lex['2'].':'.$lex[3] : '';
   				$dtg = ($x == 'select') ? 'option' : 'li';
   				$dl[] = $this->tag($dtg,$lex['0'],$lat);
   				$i++;
   				$lat = '';
   			}
   		}
   
   		$ls =(is_array($dl)) ? join(PHP_EOL,$dl) : '';
   		$tit = (!empty($tit)) ? $this->h($tit,2) : '';
   		$xa =(is_array($xatt)) ? join(',',$xatt) : '';
   		$att = $xa;
   		#for debug purposes
   		#echo '<span style="color:white">'.$att.'</span>';
   		return  $this->tag($x,$tit.$txt.$ls,$att);
   	}
   }
   
}
?>