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

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -