phppreg-replacestrtr

remove string using strtr


say it if i want to remove a word like this: ',40,15,550);context2.fillText('MY_TEXT_HERE',40,20,550);context2.fillText('

so, i want to remove ',40,15,550);context2.fillText(' and ',40,20,550);context2.fillText('

if using standart strtr is we need to create 2 condition like

$lyrics = ($_POST['utamapkanji']);
$replacements = [
            "',40,15,550);context2.fillText('" => " ",
            "',40,20,550);context2.fillText('" => " ",
            ];
            $result = strtr($lyrics , $replacements);
            ?>

result will be MY_TEXT_HERE.

what i want to do is, remove a word that begin ',40 and ended with fillText(' so, by doing this i only need to make 1 condition to remove it.


Solution

  • Try this replacement:

    $result = preg_replace("(\',40[^\']*\')", '', $lyrics);