Expert Refresh

Replacing

1) Which of the following code will output 2?





2) What is the output? <?php echo substr_replace("123456", "a", 0, 0);





3) Which is correct?







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


References