duanmei1922 2014-03-10 16:04
浏览 43
已采纳

如何用数组术语替换

I need to replace words from 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 for the change in question, added the code which is not working replacement

  • 写回答

3条回答 默认 最新

  • doume5227 2014-03-10 16:14
    关注

    Your problem is you have the string Nokian being replaced before the string Nordman Nokian. Because the single word Nokian is being matched first, the string is being transformed to Nordman NORDMAN 4 XL, and str_replace is unable to match the string Nordman Nokian. Just switch the order of your array items

    I.E. ..."Nordman Nokian ","Nokian "...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题