Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 499

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>DomNode-&#62;insert_before</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="DOM XML functions"
HREF="ref.domxml.html"><LINK
REL="PREVIOUS"
TITLE="DomNode->has_child_nodes"
HREF="function.domnode-has-child-nodes.html"><LINK
REL="NEXT"
TITLE="DomNode->is_blank_node"
HREF="function.domnode-is-blank-node.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.domnode-has-child-nodes.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.domnode-is-blank-node.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.DomNode-insert-before"
></A
>DomNode-&#62;insert_before</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN21702"
></A
><P
>    (no version information, might be only in CVS)</P
>DomNode-&#62;insert_before&nbsp;--&nbsp;
     Inserts new node as child
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN21705"
></A
><H2
>Description</H2
>object <B
CLASS="methodname"
>DomNode-&#62;insert_before</B
> ( object newnode, object refnode)<BR
></BR
><P
>&#13;     This function inserts the new node <TT
CLASS="parameter"
><I
>newnode</I
></TT
> right
     before the node <TT
CLASS="parameter"
><I
>refnode</I
></TT
>. The return value is the 
     inserted node. If you plan to do further modifications on the appended 
     child you must use the returned node.
    </P
><P
>&#13;     (PHP &#62;= 4.3 only) If <TT
CLASS="parameter"
><I
>newnode</I
></TT
> already is part of a 
     document, it will be first unlinked from its existing context. If 
     <TT
CLASS="parameter"
><I
>refnode</I
></TT
> is NULL, then <TT
CLASS="parameter"
><I
>newnode</I
></TT
>
     will be inserted at the end of the list of children.  
    </P
><P
>&#13;     <B
CLASS="function"
>domnode_insert_before()</B
> is very similar to
     <B
CLASS="function"
>domnode_append_child()</B
> as the following example shows
     which does the same as the example at
     <B
CLASS="function"
>domnode_append_child()</B
>.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN21728"
></A
><P
><B
>Example 1. Adding a child</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>include("example.inc");

if(!$dom = domxml_open_mem($xmlstr)) {
  echo "Error while parsing the document\n";
  exit;
}

$elements = $dom-&#62;get_elements_by_tagname("informaltable");
print_r($elements);
$element = $elements[0];

$newnode = $element-&#62;insert_before($element, $element);
$children = $newnode-&#62;children();
$attr = $children[1]-&#62;set_attribute("align", "left");

echo "&#60;PRE&#62;";
$xmlfile = $dom-&#62;dump_mem();
echo htmlentities($xmlfile);
echo "&#60;/PRE&#62;";</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also <B
CLASS="function"
>domnode_append_child()</B
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.domnode-has-child-nodes.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.domnode-is-blank-node.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>DomNode-&#62;has_child_nodes</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.domxml.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>DomNode-&#62;is_blank_node</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>