2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2007-06-20 22:25:43 +00:00
|
|
|
<!-- $Revision: 1.9 $ -->
|
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.substr-replace">
|
2007-06-15 19:01:26 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>substr_replace</refname>
|
|
|
|
<refpurpose>Replace text within a portion of a string</refpurpose>
|
|
|
|
</refnamediv>
|
2007-06-15 19:01:57 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-06-15 19:01:26 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>mixed</type><methodname>substr_replace</methodname>
|
|
|
|
<methodparam><type>mixed</type><parameter>string</parameter></methodparam>
|
|
|
|
<methodparam><type>string</type><parameter>replacement</parameter></methodparam>
|
|
|
|
<methodparam><type>int</type><parameter>start</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>substr_replace</function> replaces a copy of
|
|
|
|
<parameter>string</parameter> delimited by the
|
|
|
|
<parameter>start</parameter> and (optionally)
|
|
|
|
<parameter>length</parameter> parameters with the string given in
|
2007-06-15 19:01:57 +00:00
|
|
|
<parameter>replacement</parameter>.
|
2007-06-15 19:01:26 +00:00
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
2007-06-15 19:01:57 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>string</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The input string.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>replacement</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The replacement string.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>start</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If <parameter>start</parameter> is positive, the replacing will
|
|
|
|
begin at the <parameter>start</parameter>'th offset into
|
|
|
|
<parameter>string</parameter>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If <parameter>start</parameter> is negative, the replacing will
|
|
|
|
begin at the <parameter>start</parameter>'th character from the
|
|
|
|
end of <parameter>string</parameter>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>length</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
If given and is positive, it represents the length of the portion of
|
|
|
|
<parameter>string</parameter> which is to be replaced. If it is
|
|
|
|
negative, it represents the number of characters from the end of
|
|
|
|
<parameter>string</parameter> at which to stop replacing. If it
|
|
|
|
is not given, then it will default to strlen(
|
|
|
|
<parameter>string</parameter> ); i.e. end the replacing at the
|
|
|
|
end of <parameter>string</parameter>. Of course, if
|
|
|
|
<parameter>length</parameter> is zero then this function will have the
|
|
|
|
effect of inserting <parameter>replacement</parameter> into
|
|
|
|
<parameter>string</parameter> at the given
|
|
|
|
<parameter>start</parameter> offset.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2007-06-15 19:01:26 +00:00
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
2007-06-15 19:01:57 +00:00
|
|
|
The result string is returned. If <parameter>string</parameter> is an
|
|
|
|
array then array is returned.
|
2007-06-15 19:01:26 +00:00
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>substr_replace</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$var = 'ABCDEFGH:/MNRPQR/';
|
2003-12-15 16:55:22 +00:00
|
|
|
echo "Original: $var<hr />\n";
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
/* These two examples replace all of $var with 'bob'. */
|
2003-12-15 16:55:22 +00:00
|
|
|
echo substr_replace($var, 'bob', 0) . "<br />\n";
|
|
|
|
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />\n";
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
/* Insert 'bob' right at the beginning of $var. */
|
2003-12-15 16:55:22 +00:00
|
|
|
echo substr_replace($var, 'bob', 0, 0) . "<br />\n";
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
/* These next two replace 'MNRPQR' in $var with 'bob'. */
|
2003-12-15 16:55:22 +00:00
|
|
|
echo substr_replace($var, 'bob', 10, -1) . "<br />\n";
|
|
|
|
echo substr_replace($var, 'bob', -7, -1) . "<br />\n";
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
/* Delete 'MNRPQR' from $var. */
|
2003-12-15 16:55:22 +00:00
|
|
|
echo substr_replace($var, '', 10, -1) . "<br />\n";
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2007-06-15 19:01:26 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
2004-07-22 22:51:12 +00:00
|
|
|
|
2007-06-15 19:01:57 +00:00
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
2007-06-15 19:01:26 +00:00
|
|
|
¬e.bin-safe;
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
2004-07-22 22:51:12 +00:00
|
|
|
|
2007-06-15 19:01:57 +00:00
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
2007-06-15 19:01:57 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>str_replace</function></member>
|
|
|
|
<member><function>substr</function></member>
|
|
|
|
</simplelist>
|
2007-06-15 19:01:26 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2007-06-15 19:01:57 +00:00
|
|
|
|
2007-06-15 19:01:26 +00:00
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|