Replacement of specific words

-1

I want to create a code in PHP in which the user type, for example, "pedro went to the market" he replaced in a few words already registered type to exchange the syllable "mer" for copper and the syllable "went" for example. and give the text ready in another window.

I do not know where to start, any help and welcome

    
asked by anonymous 12.02.2018 / 16:29

1 answer

1

You can use the str_replace function, using arrays :

$texto  = "pedro foi ao mercado";

$de    = array("mer", "foi");
$para  = array("cobre", "casa");

$novafrase = str_replace($de, $para, $texto);

echo $novafrase;

Functional example: link

Source: function.str-replace

    
12.02.2018 / 16:42