fork download
  1. <?php
  2.  
  3. class HtmlBuilder {
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. public function makeHeader(){
  11. $header = '<ul>';
  12. foreach($this as $key => $value){
  13.  
  14. $header .= '<li><a href="'.$key.'"><span>'.ucfirst($key).'</span></a></li>';
  15. }
  16. $header .= '</ul>';
  17. return $header;
  18. }
  19.  
  20. public function makeTabs(){
  21. $result = '<div id="tabs">';
  22. $result .= $this->makeHeader();
  23. foreach($this as $key => $value){
  24. $result .= '<div id="'.$key.'">'.ucfirst($value).'</div>';
  25. }
  26. $result .= '</div>';
  27. return $result;
  28. }
  29.  
  30. }
  31.  
  32.  
  33. class Content extends HtmlBuilder{
  34.  
  35. public $prop1;
  36. public $prop2;
  37. public $prop3;
  38.  
  39.  
  40. }
  41.  
  42.  
  43. $Content = new Content();
  44. $Content->prop1 = "Test1";
  45. $Content->prop2 = "Test2";
  46. $Content->prop3 = "Test3";
  47.  
  48.  
  49.  
  50. echo $Content->makeTabs();
  51.  
  52.  
  53. ?>
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
<div id="tabs"><ul><li><a href="prop1"><span>Prop1</span></a></li><li><a href="prop2"><span>Prop2</span></a></li><li><a href="prop3"><span>Prop3</span></a></li></ul><div id="prop1">Test1</div><div id="prop2">Test2</div><div id="prop3">Test3</div></div>