Collection of all variants of str_replace function like functionality. Examples providing all kinds of solutions for your needs. From simple string replacement to regular expressions.
Source code viewer
// Regular, replaces all occurrences. // str_replace(array|string $find_string, array|string $replace_with, string|array $subject, int &$count = null): string|array print $string; // Output: search & replace // Input is array, replaces all occurrences. print $string; // Output: result // Input and replacement are arrays, replaces with corresponding values. $subject = 'ABABABAB'; print $string; // Output: BBBBBBBB // The values are replaced in a loop. So it won't be BABABABA, as you might expect intuitively. // Count the replacements. $count = 0; print $count; // Output: 1 // ireplace means you can use the function in case-insensitive mode. print $string; // Output: search & replace // Using regular expression. Parentheses are used to determinate sub-patterns. Subpattern results are put to variables such as $1, $2, etc. // preg_replace(string|array $pattern, string|array $replacement, string|array $subject, int $limit = -1, int &$count = null): string|array|nullProgramming Language: PHP