2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 09:08:43 +00:00
|
|
|
<!-- $Revision$ -->
|
2020-12-05 14:30:42 +00:00
|
|
|
<refentry xml:id="function.str-ireplace" xmlns="http://docbook.org/ns/docbook">
|
2007-06-15 19:01:26 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>str_ireplace</refname>
|
2018-01-25 15:34:22 +00:00
|
|
|
<refpurpose>Case-insensitive version of <function>str_replace</function></refpurpose>
|
2007-06-15 19:01:26 +00:00
|
|
|
</refnamediv>
|
2007-06-15 19:01:57 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-06-15 19:01:26 +00:00
|
|
|
<methodsynopsis>
|
2020-12-05 14:30:42 +00:00
|
|
|
<type class="union"><type>string</type><type>array</type></type><methodname>str_ireplace</methodname>
|
|
|
|
<methodparam><type class="union"><type>array</type><type>string</type></type><parameter>search</parameter></methodparam>
|
|
|
|
<methodparam><type class="union"><type>array</type><type>string</type></type><parameter>replace</parameter></methodparam>
|
|
|
|
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>subject</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>int</type><parameter role="reference">count</parameter><initializer>&null;</initializer></methodparam>
|
2007-06-15 19:01:26 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
This function returns a string or an array with all occurrences of
|
|
|
|
<parameter>search</parameter> in <parameter>subject</parameter>
|
|
|
|
(ignoring case) replaced with the given <parameter>replace</parameter>
|
|
|
|
value. If you don't need fancy replacing rules, you should generally
|
2008-11-28 20:34:00 +00:00
|
|
|
use this function instead of
|
2007-06-15 19:01:26 +00:00
|
|
|
<function>preg_replace</function> with the <literal>i</literal> modifier.
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2011-01-07 03:39:17 +00:00
|
|
|
<para>
|
|
|
|
If <parameter>search</parameter> and <parameter>replace</parameter> are
|
|
|
|
arrays, then <function>str_ireplace</function> takes a value from each
|
|
|
|
array and uses them to search and replace on
|
|
|
|
<parameter>subject</parameter>. If <parameter>replace</parameter> has fewer
|
|
|
|
values than <parameter>search</parameter>, then an empty string is used for
|
|
|
|
the rest of replacement values. If <parameter>search</parameter> is an
|
|
|
|
array and <parameter>replace</parameter> is a string, then this replacement
|
|
|
|
string is used for every value of <parameter>search</parameter>. The
|
|
|
|
converse would not make sense, though.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If <parameter>search</parameter> or <parameter>replace</parameter>
|
|
|
|
are arrays, their elements are processed first to last.
|
|
|
|
</para>
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
2007-06-15 19:01:57 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>search</parameter></term>
|
|
|
|
<listitem>
|
2011-01-07 03:39:17 +00:00
|
|
|
<para>
|
|
|
|
The value being searched for, otherwise known as the
|
|
|
|
<emphasis>needle</emphasis>. An array may be used to designate
|
|
|
|
multiple needles.
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>replace</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-01-07 03:39:17 +00:00
|
|
|
The replacement value that replaces found <parameter>search</parameter>
|
|
|
|
values. An array may be used to designate multiple replacements.
|
2007-06-15 19:01:57 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>subject</parameter></term>
|
|
|
|
<listitem>
|
2011-01-07 03:39:17 +00:00
|
|
|
<para>
|
|
|
|
The string or array being searched and replaced on,
|
|
|
|
otherwise known as the <emphasis>haystack</emphasis>.
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
<para>
|
|
|
|
If <parameter>subject</parameter> is an array, then the search and
|
|
|
|
replace is performed with every entry of
|
|
|
|
<parameter>subject</parameter>, and the return value is an array as
|
|
|
|
well.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>count</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2011-01-07 03:39:17 +00:00
|
|
|
If passed, this will be set to the number of replacements performed.
|
2007-06-15 19:01:57 +00:00
|
|
|
</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;
|
|
|
|
<para>
|
|
|
|
Returns a string or an array of replacements.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2007-06-15 19:01:26 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>str_ireplace</function> example</title>
|
|
|
|
<programlisting role="php">
|
2003-01-30 05:25:37 +00:00
|
|
|
<![CDATA[
|
2003-05-30 16:47:59 +00:00
|
|
|
<?php
|
2003-06-16 15:14:47 +00:00
|
|
|
$bodytag = str_ireplace("%body%", "black", "<body text=%BODY%>");
|
2016-01-15 18:15:00 +00:00
|
|
|
echo $bodytag; // <body text=black>
|
2003-05-30 16:47:59 +00:00
|
|
|
?>
|
2003-01-30 05:25:37 +00:00
|
|
|
]]>
|
2007-06-15 19:01:26 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
2009-01-02 20:04:25 +00:00
|
|
|
¬e.bin-safe;
|
2011-01-07 03:39:17 +00:00
|
|
|
<caution>
|
|
|
|
<title>Replacement order gotcha</title>
|
|
|
|
<para>
|
|
|
|
Because <function>str_ireplace</function> replaces left to right, it might
|
2011-04-04 08:44:48 +00:00
|
|
|
replace a previously inserted value when doing multiple replacements.
|
|
|
|
Example #2 in the <function>str_replace</function> documentation
|
|
|
|
demonstrates how this may affect you in practice.
|
2011-01-07 03:39:17 +00:00
|
|
|
</para>
|
|
|
|
</caution>
|
2007-06-15 19:01:57 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<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>preg_replace</function></member>
|
|
|
|
<member><function>strtr</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>
|
2003-01-30 05:25:37 +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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2003-01-30 05:25:37 +00:00
|
|
|
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
|
|
|
|
-->
|