I hope somebody can help me, i am oop starter and the script below gives output < but i want this <input type="text">.
Now i created a Build class but it doesnt work. What do i do wrong and how can i fix this?
Can somebody help me?
Thnks!
//set get Element
class Element {
private $_element;
function addElement($element) {
$this->_element = $element;
}
function getElement(){
return $this->_element;
}
}
//add and set Atrr
class attrType extends Element {
//set var
public $_attrType;
function __construct(){
$this->_attrType = array();
}
function addAttr($attrType, $attrValue){
$this->_attrType[$attrType] = $attrValue;
}
function getAttr(){
return $this->_attrType;
}
}
//build input text field
class Build extends attrType {
function Builder() {
$html .= "<";
$html .= ''.$this->getElement();
foreach( $this->getAttr() as $key => $value){
$html .= " $key=";
$html .= "\"$value\">";
}
return $html;
}
}
$element = new Element();
$attr = new attrType();
$build = new Build();
$attr->addElement('input');
$attr->addAttr('type','text');
echo $build->Builder();
Change your code as shown below
instead of
Thanks