[Solved] Replace value in str [closed]


Use str_ireplace() to replace case insensitive in a string.

In your case:

EDIT: even better without loop and now your array can contain also lowercase:

<?php
    $str= str_ireplace($arr, array_map('strtoupper',$arr) , $str);
?>

(asssuming all values in $arr are upper case as in your example)

Adding a fix according to Mark’s note:

<?php
    foreach($arr as $value){
        $str= str_ireplace(' '.$value.' ', ' '.strtoupper($value).' ' , $str);
    }
?>

(You can also loop $arr and add spaces before and after each word then run it as in the first example)

10

solved Replace value in str [closed]