我与symfony合作 我想在示例的特定“ id”之后添加我拥有的任何元素
我有这个html
<ul>
<li id="li-0">
<a href="#"><span>All Products</span></a>
</li>
<li id="li-2" class="">
<a href="#"><span>Features</span>/a>
</li>
我想添加<li id="li-1" ><a href="#"><span>Testimonials</span></a></li>
具有id li-0的元素之后
`
$crawler = new Crawler();
$htmlContent='<ul>
<li id="li-0">
<a href="#"><span>All Products</span></a>
</li>
<li id="li-3" class="">
<a href="#"><span>Features</span>/a>
</li>
</ul>';
$crawler->addHtmlContent($htmlContent, 'UTF-8');
$newNode = new Crawler();
$newNode->addHtmlContent('<li id="li-2" ><a href="#"><span>Testimonials</span></a></li>', 'UTF-8');
$node=$crawler->children()->filter('#li-0')->getNode(0);
$node->parentNode->insertBefore($newNode->children()->getNode(0));