Generating code with php-class-html-generator

I am trying to reproduce the following markup with php-class-html-generator , but I am stuck with the insert <i> and setting the text at the end, before </h4>

Original html

 <h4 class="formTitle lead"> <span class="widget-number"><i class="icon-comments"></i></span>Random </h4> 

My code is:

 $h4 = HTMLTag::createElement('h4')->setText("Random") ->addClass('formTitle') ->addClass('lead'); $h4->addElement('span') ->addClass('widget-number'); return($h4); 

My conclusion at the moment:

 <h4 class="formTitle lead"> <span class="widget-number">Random</span> </h4> 


Thank you for your help!

+4
source share
1 answer

Try it -

 $h4 = HTMLTag::createElement('h4')->setText("Random")->addClass('formTitle')->addClass('lead'); $span = $h4->addElement('span')->addClass('widget-number'); $i = $span->addElement('i')->setText(' ')->addClass('icon-comments'); 

Result -

  <h4 class="formTitle lead"> <span class="widget-number"> <i class="icon-comments"></i></span>Random</h4> 
+3
source

All Articles