Replace multiple words with Str_Replace

后端 未结 5 2236
醉梦人生
醉梦人生 2021-01-05 18:50

I want to replace multiple synonyms with one specific word.



        
5条回答
  •  甜味超标
    2021-01-05 19:25

    I found a very easy solution to replace multiple words in a string :

     
    

    output :

      Honda is a car. 
    Toyota is a car. 
    Nissan is a car. 
    Scion is a car
    

    With this script you can replace as many words in a string as you want :

    just place the word (that you want to replace) in the pattern array , eg :

         $pattern[0]="/replaceme/"; 
    

    and place the characters (that will be used in place of the replaced characters) in the replacement array, eg :

          $replacement[0]="new_word"; 
    

    Happy coding!

提交回复
热议问题