svn: /phpdoc/en/trunk/reference/strings/functions/ substr-replace.xml

From: Date: Tue, 19 Apr 2011 07:22:19 +0000
Subject: svn: /phpdoc/en/trunk/reference/strings/functions/ substr-replace.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-7978@lists.php.net to get a copy of this message
aharvey Tue, 19 Apr 2011 07:22:19 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=310346 Log: Fix doc bug #54519 (substr_replace array options not documented) by providing some minimal documentation of the array parameter options available. Bug: http://bugs.php.net/54519 (Assigned) substr_replace array options not documented Changed paths: U phpdoc/en/trunk/reference/strings/functions/substr-replace.xml Modified: phpdoc/en/trunk/reference/strings/functions/substr-replace.xml =================================================================== --- phpdoc/en/trunk/reference/strings/functions/substr-replace.xml 2011-04-19 06:27:54 UTC (rev 310345) +++ phpdoc/en/trunk/reference/strings/functions/substr-replace.xml 2011-04-19 07:22:19 UTC (rev 310346) @@ -11,9 +11,9 @@ <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> + <methodparam><type>mixed</type><parameter>replacement</parameter></methodparam> + <methodparam><type>mixed</type><parameter>start</parameter></methodparam> + <methodparam choice="opt"><type>mixed</type><parameter>length</parameter></methodparam> </methodsynopsis> <para> <function>substr_replace</function> replaces a copy of @@ -34,6 +34,15 @@ <para> The input string. </para> + <para> + An <type>array</type> of <type>string</type>s can be provided, in which + case the replacements will occur on each string in turn. In this case, + the <parameter>replacement</parameter>, <parameter>start</parameter> + and <parameter>length</parameter> parameters may be provided either as + scalar values to be applied to each input string in turn, or as + <type>array</type>s, in which case the corresponding array element will + be used for each input string. + </para> </listitem> </varlistentry> <varlistentry> @@ -89,11 +98,35 @@ </para> </refsect1> + <refsect1 role="changelog"> + &reftitle.changelog; + <para> + <informaltable> + <tgroup cols="2"> + <thead> + <row> + <entry>&Version;</entry> + <entry>&Description;</entry> + </row> + </thead> + <tbody> + <row> + <entry>4.3.3</entry> + <entry> + All parameters now accept <type>array</type>s. + </entry> + </row> + </tbody> + </tgroup> + </informaltable> + </para> + </refsect1> + <refsect1 role="examples"> &reftitle.examples; <para> <example> - <title><function>substr_replace</function> example</title> + <title>Simple <function>substr_replace</function> examples</title> <programlisting role="php"> <![CDATA[ <?php @@ -118,6 +151,40 @@ </programlisting> </example> </para> + <para> + <example> + <title> + Using <function>substr_replace</function> to replace multiple strings at + once + </title> + <programlisting role="php"> +<![CDATA[ +<?php +$input = array('A: XXX', 'B: XXX', 'C: XXX'); + +// A simple case: replace XXX in each string with YYY. +echo implode('; ', substr_replace($input, 'YYY', 3, 3))."\n"; + +// A more complicated case where each replacement is different. +$replace = array('AAA', 'BBB', 'CCC'); +echo implode('; ', substr_replace($input, $replace, 3, 3))."\n"; + +// Replace a different number of characters each time. +$length = array(1, 2, 3); +echo implode('; ', substr_replace($input, $replace, 3, $length))."\n"; +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +A: YYY; B: YYY; C: YYY +A: AAA; B: BBB; C: CCC +A: AAAXX; B: BBBX; C: CCC +]]> + </screen> + </example> + </para> </refsect1> <refsect1 role="notes">

« previous php.doc.cvs (#7978) next »