Memory App
 




String replace

Replaces all occurrences of the search string with the replacement string

echo str_replace("EN ", "RO ", "EN dictionary for En class");

// RO dictionary for En class

echo str_ireplace("EN ", "RO ", "EN dictionary for En class", $count);

// RO dictionary for RO class; $count = 2

echo str_ireplace(array('RO ', 'EN '), 'RU ', 'ro class for en students');

// RU class for RU students

echo str_ireplace(array('RO ', 'EN '), array('RU ', 'IT '), 'ro class for en students');

// RU class for IT students
(1/3)

Strstr

Translates characters or replace substrings.

echo strtr("baab", "ab", "01"); // Output: 1001

// Single character version (replace bytes)
    
echo str_replace("ab", "01", "baab"); // Output: ba01

// Different from str_replace (replace substrings)
    
echo strtr("This is America", array('This'=>'Acesta', 'is'=>'e')); 

// Multiple-character version (replace substrings)
// Acesta e America
(2/3)

Substring replace

Returns: string OR array

echo substr_replace("123456", "a", 0); // Output: a
echo substr_replace("123456", "a", 2); // Output: 12a
echo substr_replace("123456", "a", -1); // Output: 12345a
echo substr_replace("123456", "a", -2); // Output: 1234a
echo substr_replace("123456", "a", 0, 2); // Output: a3456
echo substr_replace("123456", "a", 0, -2); // Output: a56
echo substr_replace("123456", "a", 0, 0); // Output: a23456


Questions