php - How to replace by array terms -


i need replace words text

    $test = "nordman nokian nordman 4 xl"; $replaces = array("amtel " ,"bridgestone " ,"continental " ,"cordiant " ,"dunlop " ,"formula " ,"gislaved " ,"kingstar " ,"bfgoodrich " ,"goodyear " ,"hankook " ,"headway " ,"fulda " ,"hifly " ,"kumho " ,"gremax " ,"matador " ,"michelin " ,"rosava " ,"nankang " ,"nokian " ,"nordman nokian " ,"pirelli " ,"radial " ,"sava " ,"tigar " ,"toyo " ,"viatti " ,"maxxis " ,"yokohama "); echo str_replace($replaces, "", $test); // return nordman nordman 4 xl 

the desired result

// return nordman 4 xl 

i apologize change in question, added code not working replacement

your problem have string nokian being replaced before string nordman nokian. because single word nokian being matched first, string being transformed nordman nordman 4 xl, , str_replace unable match string nordman nokian. switch order of array items

i.e. ..."nordman nokian ","nokian "...


Comments

Popular posts from this blog

google app engine - 403 Forbidden POST - Flask WTForms -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -

how to run a query SQL in node.js mysql -