本文整理汇总了PHP中DOMText::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMText::insertBefore方法的具体用法?PHP DOMText::insertBefore怎么用?PHP DOMText::insertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMText
的用法示例。
在下文中一共展示了DOMText::insertBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
/**
* Inserts a new child immediately after the specified frame
*
* @param $new_child Frame The new Frame to insert
* @param $ref Frame The Frame before the new Frame
* @param $update_node boolean Whether or not to update the DOM
*
* @throws DOMPDF_Exception
*/
function insert_child_after(Frame $new_child, Frame $ref, $update_node = true)
{
if ($ref === $this->_last_child) {
$this->append_child($new_child, $update_node);
return;
}
if (is_null($ref)) {
$this->prepend_child($new_child, $update_node);
return;
}
if ($ref->_parent !== $this) {
throw new DOMPDF_Exception("Reference child is not a child of this node.");
}
// Update the node
if ($update_node) {
if ($ref->_next_sibling) {
$next_node = $ref->_next_sibling->_node;
$this->_node->insertBefore($new_child->_node, $next_node);
} else {
$new_child->_node = $this->_node->appendChild($new_child->_node);
}
}
// Remove the child from its parent
if ($new_child->_parent) {
$new_child->_parent->remove_child($new_child, false);
}
$new_child->_parent = $this;
$new_child->_prev_sibling = $ref;
$new_child->_next_sibling = $ref->_next_sibling;
if ($ref->_next_sibling) {
$ref->_next_sibling->_prev_sibling = $new_child;
}
$ref->_next_sibling = $new_child;
}