Replace multiple words with Str_Replace

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

I want to replace multiple synonyms with one specific word.



        
5条回答
  •  情深已故
    2021-01-05 19:03

    Something like

    $a = array( 'truck', 'vehicle', 'seddan', 'coupe' ); 
    
    $str = 'Honda is a truck. Toyota is a vehicle. Nissan is a sedan. Scion is a coupe.'; 
    
    echo str_replace($a,'car',$str); 
    

    Should work.

    http://codepad.org/1LhtcOSR

    Edit:

    Something like this should yield expected results: http://pastebin.com/xGzYiCk3

    $text = '{test|test2|test3} some other stuff {some1|some2|some3}';
    

    Output:

    test3 some other stuff some1
    test2 some other stuff some2
    test3 some other stuff some3
    test3 some other stuff some1
    

提交回复
热议问题