Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > ebb1914cf182a88528b4547490db1dd8 > files > 1494

kdewebdev-quanta-doc-3.5.9-2mdv2008.1.x86_64.rpm

<HTML
><HEAD
><TITLE
>substr_replace</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="manual.html"><LINK
REL="UP"
TITLE="String functions"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="substr"
HREF="function.substr.html"><LINK
REL="NEXT"
TITLE="trim"
HREF="function.trim.html"></HEAD
><BODY
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><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.substr.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.trim.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.substr-replace"
>substr_replace</A
></H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN26810"
></A
>substr_replace -- Replace text within a portion of a string.</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26813"
></A
><H2
>Description</H2
><DIV
CLASS="funcsynopsis"
><P
></P
><CODE
CLASS="FUNCDEF"
>string substr_replace</CODE
>(string string, string replacement, int start, int 
      [<SPAN
CLASS="optional"
>length</SPAN
>]
     );<P
></P
></DIV
><P
>&#13;     <B
CLASS="function"
>substr_replace()</B
> replaces the part of
     <TT
CLASS="parameter"
><I
>string</I
></TT
> delimited by the
     <TT
CLASS="parameter"
><I
>start</I
></TT
> and (optionally)
     <TT
CLASS="parameter"
><I
>length</I
></TT
> parameters with the string given in
     <TT
CLASS="parameter"
><I
>replacement</I
></TT
>. The result is returned.
    </P
><P
>&#13;     If <TT
CLASS="parameter"
><I
>start</I
></TT
> is positive, the replacing will
     begin at the <TT
CLASS="parameter"
><I
>start</I
></TT
>'th offset into
     <TT
CLASS="parameter"
><I
>string</I
></TT
>.  
    </P
><P
>&#13;     If <TT
CLASS="parameter"
><I
>start</I
></TT
> is negative, the replacing will
     begin at the <TT
CLASS="parameter"
><I
>start</I
></TT
>'th character from the
     end of <TT
CLASS="parameter"
><I
>string</I
></TT
>.  
    </P
><P
>&#13;     If <TT
CLASS="parameter"
><I
>length</I
></TT
> is given and is positive, it
     represents the length of the portion of
     <TT
CLASS="parameter"
><I
>string</I
></TT
> which is to be replaced. If it is
     negative, it represents the number of characters from the end of
     <TT
CLASS="parameter"
><I
>string</I
></TT
> at which to stop replacing. If it
     is not given, then it will default to strlen(
     <TT
CLASS="parameter"
><I
>string</I
></TT
> ); i.e. end the replacing at the
     end of <TT
CLASS="parameter"
><I
>string</I
></TT
>.
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><P
><B
>Example 1. <B
CLASS="function"
>Substr_replace()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>  1&nbsp;
  2&nbsp;&#60;?php
  3&nbsp;$var = 'ABCDEFGH:/MNRPQR/';
  4&nbsp;echo "Original: $var&#60;hr&#62;\n";
  5&nbsp;
  6&nbsp;/* These two examples replace all of $var with 'bob'. */
  7&nbsp;echo substr_replace ($var, 'bob', 0) . "&#60;br&#62;\n";
  8&nbsp;echo substr_replace ($var, 'bob', 0, strlen ($var)) . "&#60;br&#62;\n";
  9&nbsp;
 10&nbsp;/* Insert 'bob' right at the beginning of $var. */
 11&nbsp;echo substr_replace ($var, 'bob', 0, 0) . "&#60;br&#62;\n";
 12&nbsp;
 13&nbsp;/* These next two replace 'MNRPQR' in $var with 'bob'. */
 14&nbsp;echo substr_replace ($var, 'bob', 10, -1) . "&#60;br&#62;\n";
 15&nbsp;echo substr_replace ($var, 'bob', -7, -1) . "&#60;br&#62;\n";
 16&nbsp;
 17&nbsp;/* Delete 'MNRPQR' from $var. */
 18&nbsp;echo substr_replace ($var, '', 10, -1) . "&#60;br&#62;\n";
 19&nbsp;?&#62;
 20&nbsp;      </PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also <A
HREF="function.str-replace.html"
><B
CLASS="function"
>str_replace()</B
></A
> and
     <A
HREF="function.substr.html"
><B
CLASS="function"
>substr()</B
></A
>.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      <B
CLASS="function"
>Substr_replace()</B
> was added in PHP 4.0.
     </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.substr.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="manual.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.trim.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>substr</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>trim</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>