str_ireplace 


string apg

REPLACE all occurrences of the search STRING with the replacement STRING.

Case-insensitive version of str_replace.





If $search and $replace are ARRAYS, this function takes a value from each ARRAY and uses them to search and replace on $subject.

If $replace has fewer values than $search, then an empty STRING is used for the rest of replacement values.

If $search is an ARRAY and $replace is a STRING, then this replacement STRING is used for every value of $search.

The opposite is meaningless, however.

If $search or $replace are ARRAYS, their elements are processed first to last.

If $subject is an ARRAY, then the search and replace is performed with every entry of $subject, and the return value is an ARRAY as well.

This function returns a STRING or an ARRAY with the replaced values.

This function is binary-safe

This functions replaces left to right, it might replace a previously inserted value when doing multiple replacements.



<?php

mix str_ireplace 
mix $search 
                            
mix $replace 
                            
mix $subject [, 
                            
int &$count ] )


where,

$search The needle or ARRAY of 
                           needles to be searched 
for

$replace The replacement value or ARRAY 
                           
of values that replaces found search values

$replace 
The haystackSTRING or ARRAY 
                           
being searched and replaced on

&$count The number of performed replacements

?>

$search


The needle or ARRAY of needles to be searched for.



$replace


The replacement value or ARRAY of values that replaces found search values.



$suject


The haystack, STRING or ARRAY being searched and replaced on.



&$count


The number of performed replacements.



  1 EXERCISE   

<?php 

$str01 
"Everything what is said on something, 
           does not have to be necessarily a REPLY!"
;
           
$strsb01a "TRUE!"
$strsb01b "LIE!"

$rtvl01a "Everything what is said on something, 
           does not have to be necessarily a TRUE!"
;
           
$rtvl01b "Everything what is said on something, 
           does not have to be necessarily a LIE!"
;

$cnt01a 72;
$cnt01b = -6;

echo 
$str01 '<br><br>'
echo 
'$strsb01a = ' $strsb01a '<br>'
echo 
'$strsb01b = ' $strsb01b '<br><br>';

echo 
'$rtvl01a = ' $rtvl01a '<br>'
echo 
'$rtvl01b = ' $rtvl01b 
'<br><br>- - - - - - - - - - - -<br><br>'

echo 
"str_ireplace ($str01$strsb01a$rtvl01a$cnt01a)<br><br>"
$vlr101a str_ireplace ($str01$strsb01a$rtvl01a$cnt01a); 
echo 
$vlr101a 
'<br><br><br>- - - - - - - - - - - -<br><br>'

echo 
"str_ireplace ($str01$strsb01b$rtvl01b$cnt01b)<br><br>"
$vlr101b str_ireplace ($str01$strsb01b$rtvl01b$cnt01b); 
echo 
$vlr101b 
'<br><br>- - - - - - - - - - - -<br><br>'


?> 

  2 EXERCISE   

<?php

$nedl02l 
= ['cao''me'];

$nedl02u = ['CAO''ME'];

$rpl02 = ['ção''mé'];

$sbj02 'Estruturacao Geometrica.';

$acstr02l str_ireplace($nedl02l$rpl02$sbj02$cnt02);

// To replace cao by ção and me by mé

// Estruturação Geométrica(PORTUGUESE) = 
// = Geometric Structuring(ENGLISH)
 
echo $acstr02l ' (' $cnt02 ')<br><br>';

$acstr02u str_ireplace($nedl02u$rpl02$sbj02$cnt02);

echo 
$acstr02u ' (' $cnt02 ')<br>';

?>

  3 EXERCISE   

<?php

$nedl03 
= ['GEOMETRIC''structuring'];

$rpl03 = ['GEOMETRIC''STRUCTURING'];

$sbj03 'geometric structuring.'

$acstr03 str_ireplace($nedl03$rpl03$sbj03$ct03);
 
echo 
$acstr03 ' ( ' $ct03 ' )';

?> 

  4 EXERCISE   

<?php

$nedl04 
= ['T''B''a''D''e'];

$rpl04 = ['A''X''D''f''E'];

$sbj04  'Better to ask the way than go astray.';

$acstr04 str_ireplace($nedl04$rpl04$sbj04$ct04);
 
echo 
$acstr04 ' ( ' $ct04 ' )';

?> 

  5 EXERCISE   

<?php

var_dump
(str_ireplace(""""""));
echo 
'<br><br>';
var_dump(str_ireplace("tt""a""ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace("tt""a""ttttTttttttttTT"$count));
var_dump($count);
echo 
'<br><br><br>';
var_dump(str_ireplace("tt""aa""ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace("tt""aa""ttttTttttttttTT"$count));
var_dump($count);
echo 
'<br><br><br>';
var_dump(str_ireplace("tt""aaa""ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace("tt""aaa""ttttTttttttttTT"$count));
var_dump($count);
echo 
'<br><br><br>';
var_dump(str_ireplace("tt""aaa""ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace("tt""aaa""ttttTttttttttTT"$count));
var_dump($count);
echo 
'<br><br><br>';
var_dump(str_ireplace(array("tt""tt"), "aaa""ttttTttttttttTT"));
echo 
'<br><br><br>';
var_dump(str_ireplace(array("tt""tt"), 
                array(
"aaa"), "ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace(array("tt""y"), 
              array(
"aaa""bbb"), "ttttTttttttttTT"));
echo 
'<br><br><br>';
var_dump(str_ireplace(array("tt""tt"), "aaa""ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace(array("tt""tt"), 
                  array(
"aaa"), "ttttTttttttttTT"));
echo 
'<br><br>';
var_dump(str_ireplace(array("tt""y"), 
           array(
"aaa""bbb"), "ttttTttttttttTT"));
echo 
'<br><br><br>';
var_dump(str_ireplace(array("tt""y"), 
           array(
"aaa""bbb"), 
           array(
"ttttTttttttttTT""aayyaayasdayYahsdYYY")));
echo 
'<br><br>';
var_dump(str_ireplace(array("tt""y"), 
                         array(
"aaa""bbb"), 
                         array(
"key"=>"ttttTttttttttTT"
                         
"test"=>"aayyaayasdayYahsdYYY")));
echo 
'<br><br>';
var_dump(str_ireplace(array("t"=>"tt""y"=>"y"), 
             array(
"a"=>"aaa""b"=>"bbb"), 
             array(
"key"=>"ttttTttttttttTT"
             
"test"=>"aayyaayasdayYahsdYYY")));

/* separate testcase for str_ireplace() off-by-one */
echo '<br><br><br><br>';
$Data "Change tracking and management 
    software designed to watch for abnormal 
    system behavior.\nSuggest features, report bugs, 
    or ask questions here."
;
var_dump($Data str_ireplace("\r\n""<br>"$Data));
echo 
'<br><br>';
var_dump($Data str_ireplace("\n""<br>"$Data));

?>