Friday 15 June 2012

insert html markup to php html string -



insert html markup to php html string -

i'm using builtin method returns html string:

var $stuff = $this->getblock();

where $stuff is:

<p>lorem ipsum</p> <ul> <li>foo<span>bar</span></li> <li>foo<span>bar</span></li> <li>foo<span>bar</span></li> . . . </ul>

what i'd add together 2 more list elements end of list. how can that? tokenize $stuff? or there easier way that?

thanks!

look next dom functions/classes in php:

the domdocument class

domdocument::createelement

here's illustration of how asking:

$stuff = "<p>lorem ipsum</p><ul><li>foo<span>bar</span></li><li>foo<span>bar</span> </li><li>foo<span>bar</span></li></ul>"; $dom = new domdocument(); $dom->loadhtml($stuff); $element1 = $dom->createelement('li', 'test'); $element2 = $dom->createelement('li', 'test'); $list = $dom->getelementsbytagname('ul'); $list->item(0)->appendchild($element1); $list->item(0)->appendchild($element2); echo $dom->savehtml();

you can replace $stuff

$stuff = $this->getblock();

php

No comments:

Post a Comment