Studyon Minte9.com
ZCE 5.3

Study

Replacing



	// str_replace(search, replace, subject) [, &count] | str_ireplace("EN ", "RO ", "EN for En", $count) 
	// strtr(subject, from, to) | strtr("baab", "ab", "01") = 1001
	// substr_replace(subject, replacement, start) [, length] | substr_replace("1234", "a", 2) = 12a


str_replace() -  replaces all occurrences of the search string with the replacement string

<?php 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
  strtr() - translates characters or replace substrings
<?php 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
  substr_replace()
<?php // substr_replace ($string, $replacement, $start) [, $length ] // 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