str_replace 


string apg

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

This function is an case-sensitive version of str_ireplace.





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_replace 
( 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 haystack, STRING 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 = 72;
$rtvl01b = -6;

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

echo 
'$rtvl01a = ' . $rtvl01a . '<br>'; 
echo 
'$rtvl01b = ' . $rtvl01b . '<br><br>'; 

echo 
"str_replace ($str01, $strsb01a, $rtvl01a)<br><br>"; 
$vlr101a = str_replace ($str01, $strsb01a, $rtvl01a); 
var_dump($vlr101a); 
echo 
'<br><br><br>'; 

echo 
"str_replace ($str01, $strsb01b, $rtvl01b)<br><br>"; 
$vlr101b = str_replace ($str01, $strsb01b, $rtvl01b); 

var_dump($vlr101b); 

?> 

  2 EXERCISE   

<?php

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

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

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

$sbj02 = 'Estruturacao Geometrica.';

$acstr02l = str_replace($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_replace($nedl02u, $rpl02, $sbj02, $cnt02);

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

?>

  3 EXERCISE   

<?php

$nedl03 
= ['G', 'S'];

$rpl03 = ['g', 's'];

$sbj03 = 'geometric structuring.'; 

$acstr03 = str_replace($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_replace($nedl04, $rpl04, $sbj04, $ct04);
 
echo 
$acstr04 . ' ( ' . $ct04 . ' )';

?> 

  5 EXERCISE   

<?php

$data 
= ['a' => 'b', 'numeric' => 1];
$ref = &$data;
$b = &$ref['a'];
$numeric = &$ref['numeric'];

var_dump(str_replace(array_keys($data), 
                                                     
$data, 
                                                    
"a numeric"));
echo 
"<br><br>";
var_dump($numeric);
echo 
"<br><br>";
var_dump($data['numeric']);

?>

  6 EXERCISE   

<?php

echo "Testing str_replace() 
                    on basic operations.<br>"
;

var_dump( str_replace("", "", "") );
echo 
'<br><br>';
var_dump( str_replace("e", "b", "test") );
echo 
'<br><br>';
var_dump( str_replace("", "", "", $count) );
echo 
'<br><br>';
var_dump( $count );
echo 
'<br><br>';
var_dump( str_replace("q", "q", "q", $count) );
echo 
'<br><br>';
var_dump( $count );
echo 
'<br><br><br>';
var_dump( str_replace("long string here", "", "", $count) );
echo 
'<br><br>';
var_dump( $count );
echo 
'<br><br><br>';

$fp = fopen( __FILE__, "r" );
$fp_copy = $fp;
try {
    
var_dump( str_replace($fp_copy, 
                                        
$fp_copy, 
                                        
$fp_copy, 
                                        
$fp_copy) );
} catch (
TypeError $e) {
    echo 
$e->getMessage(), "<br>";
}
var_dump( $fp_copy );
echo 
'<br><br>';
fclose($fp);

?>

  7 EXERCISE   

<?php

$closure 
= function (array $array, array $keys, $value)
{
    
$current = &$array;
    foreach (
$keys as $key)
        
$current = &$current[$key];
    
$current = $value;
    return 
$array;
};

class 
SomeClass { public $prop; }

$obj = new SomeClass;
$obj->prop = ['x' => 'property'];
$obj->prop = $closure($obj->prop, ['x'], 'a');
var_dump(str_replace(array_keys($obj->prop), 
                                                     
$obj->prop, 
                                                     
"x property"));
echo 
'<br><br>';
$array = ['x' => 'property'];
$array = $closure($array, ['x'], 'a');
var_dump(str_replace(array_keys($array), 
                                                     
$array, 
                                                     
"x property"));

?>

  8 EXERCISE   

<?php

echo "Testing str_replace() 
                    with various search values.<br>"
;

$search_arr = [ TRUE, FALSE, 1, 0, -1, "1", "0", "-1",  NULL,
                     [], 
"php", ""];

$i = 0;
/* loop through to replace the 
       matched elements in the array */
foreach( $search_arr as $value ) {
  echo 
"<br><br>Iteration: $i<br>";
  
/* replace the string in array */
  
echo "str_replace($value, \"FOUND\", 
                             
$search_arr, 
                             
$count) )<br>";
  
var_dump( str_replace($value, "FOUND", 
                                      
$search_arr, $count) );
   echo 
'<br>';
   
var_dump( $count );
  
$i++;
}

?>

  9 EXERCISE   

<?php
/*
  Description: 
      Replace all occurrences of 
      the search string with
      the replacement string
*/

echo "Testing str_replace() with various subjects.<br>";

$subject = "Hello, world,0120333.3445-1.234567
          NULL TRUE FALSE\000
        \x000\x5ACD\0abcd \xXYZ\tabcd $$@#%^&*!
        ~,.:;?: !!Hello, World
        ?Hello, World chr(0).chr(128).chr(234).
        chr(65).chr(255).chr(256)"
;

/* needles in an array to be compared
           in the string $string */
           
$search_str = array (
  
"Hello, World",
  
'Hello, World',
  
'!!Hello, World',
  
"??Hello, World",
  
"$@#%^&*!~,.:;?",
  
"123",
  
123,
  
"-1.2345",
  -
1.2344,
  
"abcd",
  
'XYZ',
  
NULL,
  
"NULL",
  
"0",
  
0,
  
"",
  
" ",
  
"\0",
  
"\x000",
  
"\x5AC",
  
"\0000",
  
".3",
  
TRUE,
  
"TRUE",
  
"1",
  
1,
  
FALSE,
  
"FALSE",
  
" ",
  
"          ",
  
'b',
  
'\t',
  
"\t",
  
chr(128).chr(234).chr(65).chr(255).chr(256),
  
$subject
);

/* loop through to get the  $string */
for( $i = 0; $i < count($search_str); $i++ ) {
  echo 
"<br><br>Iteration: $i<br>";
  echo 
"<br>String after replacing the search value is =><br>";
  
var_dump( str_replace($search_str[$i], 
                                     
"FOUND", 
                                     
$subject, 
                                     
$count) );
  echo 
"<br>search string has found '$count' times<br>";
}

?>

  10 EXERCISE   

<?php

/*
  Description: 
             Replace all occurrences of 
             the search string with
             the replacement string
*/


echo "Testing Miscellaneous input data.<br>";
/*  If replace has fewer values than search, then an empty
    string is used for the rest of replacement values */
var_dump( str_replace(array("a", "a", "b"),
              array(
"q", "q"),
              
"aaabb", $count
             
)
    );
var_dump($count);
var_dump( str_replace(array("a", "a", "b"),
                      array(
"q", "q"),
                      array(
"aaa", "bbb", "ccc"),
                      
$count
                     
)
        );
var_dump($count);


echo 
"<br><br>Testing objects:<br>";
/* we get "Recoverable fatal error: 
        saying Object of class could 
        not be converted to string" 
        by default, when an object 
        is passed instead of string:
        
        The error can be  avoided by choosing 
        the __toString magix method as follows: */

class subject
{
  function 
__toString() {
    return 
"Hello, world";
  }
}
$obj_subject = new subject;

class 
search
{
  function 
__toString() {
    return 
"Hello, world";
  }
}
$obj_search = new search;

class 
replace
{
  function 
__toString() {
    return 
"Hello, world";
  }
}
$obj_replace = new replace;

var_dump(str_replace("$obj_search", 
                                   
"$obj_replace", 
                                   
"$obj_subject", 
                                   
$count));
var_dump($count);


echo 
"<br><br>Testing arrays:<br>";
var_dump(str_replace(array("a", "a", "b"), 
                                     
"multi", "aaa", $count));
var_dump($count);

var_dump(str_replace( array("a", "a", "b"),
                      array(
"q", "q", "c"),
                      
"aaa", $count
                    
)
);
var_dump($count);

var_dump(str_replace( array("a", "a", "b"),
                      array(
"q", "q", "c"),
                      array(
"aaa", "bbb"),
                      
$count
                    
)
);
var_dump($count);

try {
    
str_replace("a", array("q", "q", "c"), array("aaa"), $count);
} catch (
TypeError $exception) {
    echo 
$exception->getMessage() . "<br>";
}

var_dump(str_replace("a", 1, array("aaa", "bbb"), $count));
var_dump($count);

var_dump(str_replace(1, 3, array("aaa1", "2bbb"), $count));
var_dump($count);


echo 
"<br><br>Testing Resources:<br>";
$resource1 = fopen( __FILE__, "r" );
$resource2 = opendir( "." );
try {
    
var_dump(str_replace("stream", "FOUND", 
                                               
$resource1, $count));
} catch (
TypeError $e) {
    echo 
$e->getMessage(), "<br>";
}
try {
    
var_dump(str_replace("stream", "FOUND", 
                                                
$resource2, $count));
} catch (
TypeError $e) {
    echo 
$e->getMessage(), "<br>";
}


echo 
"<br><br>Testing a longer and heredoc string:<br>";
$string = <<<EOD
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
@#$%^&**&^%$#@!~:())))((((&&&**%$###
@@@!!!~~~~@###$%^&*
abcdefghijklmnopqrstuvwxyz0123456789
abcdefghijklmnopqrstuvwxyz0123456789
EOD;

var_dump( str_replace("abcdef", "FOUND", $string, $count) );
var_dump( $count );

echo 
"<br><br>Testing a heredoc null string:<br>";
$str = <<<EOD
EOD;
var_dump( str_replace("", "FOUND", $str, $count) );
var_dump( $count );


echo 
"<br><br>Testing simple and complex syntax strings:<br>";
$str = 'world';

/* Simple syntax */
var_dump( str_replace("world", "FOUND", "$str") );
var_dump( str_replace("world'S", "FOUND", "$str'S") );
var_dump( str_replace("worldS", "FOUND", "$strS") );

/* String with curly braces, complex syntax */
var_dump( str_replace("worldS", "FOUND", "${str}S") );
var_dump( str_replace("worldS", "FOUND", "{$str}S") );


fclose($resource1);
closedir($resource2);

?>

  11 EXERCISE   

<?php

$str 
= "try this";
$repl = "bala ";
$start = 2;
echo 
"<br><br>- - - - - - - - - -<br><br>";

echo 
"substr_replace('$str', '$repl', $start):<br>";
var_dump(substr_replace($str, $repl, $start));
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = 3;
echo 
"substr_replace('$str', '$repl', $start, $len):<br>";
var_dump(substr_replace($str, $repl, $start, $len));
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = 0;
echo 
"substr_replace('$str', '$repl', $start, $len):<br>";
var_dump(substr_replace($str, $repl, $start, $len));
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = -2;
echo 
"substr_replace('$str', '$repl', $start, $len):<br>";
var_dump(substr_replace($str, $repl, $start, $len));
echo 
"<br><br>= = = = = = = =<br><br>";

$str = "try this";
$repl = array("bala ");
$start = 4;
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).", ".
var_dump($start,1)."")."<br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).", ".
var_dump($start,1)."")."<br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala");
$repl = array("bala ");
$start = array(4);
$len = array(3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".
var_dump($repl,1).", ".var_dump($start,1)."")."<br><br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = array(3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).", ".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = array(0);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).", ".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$len = array(-2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).", ".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala");
$repl = "bala ";
$start = 4;
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = 4;
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = 4;
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = 4;
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = 4;
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = 4;
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = 4;
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala");
$repl = "bala ";
$start = array(4);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4);
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4);
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4);
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4);
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala");
$repl = "bala ";
$start = array(4,2);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).")")."<br>";
var_dump(substr_replace($str, $repl, $start))."<br><br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = 3;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = 0;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = -2;
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala");
$repl = "bala ";
$start = array(4,2);
$len = array(3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(0);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(0);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(-2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(-2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala");
$repl = "bala ";
$start = array(4,2);
$len = array(3,2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start))."<br>";
echo 
"<br><br>= = = = = = = =<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(3,2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(3,2);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(0,0);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(0,0);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = array("bala ");
$start = array(4,2);
$len = array(-2,-3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

$str = array("ala portokala", "try this");
$repl = "bala ";
$start = array(4,2);
$len = array(-2,-3);
echo 
str_replace("<br>","","substr_replace(".
var_dump($str,1).", ".var_dump($repl,1).",".
var_dump($start,1).", ".var_dump($len,1).")")."<br><br>";
var_dump(substr_replace($str, $repl, $start, $len))."<br>";
echo 
"<br><br>- - - - - - - - - -<br><br>";

?>