duanqin7791 2017-08-20 10:10
浏览 13
已采纳

用正则表达式连续查找/替换[复制]

This question already has an answer here:

Say I want to erase any quote from this string, and then replace spaces with '&', in php. I could easily do with 2 consecutive preg_replace or the like, but how to do it in only 1 passage?

" columns="4" link="file" ids="280,281,282,283,284,285,286,287,288""

to:

columns=4&link=file&ids=280,281,282,283,284,285,286,287,288
</div>
  • 写回答

1条回答 默认 最新

  • doulan8846 2017-08-20 10:15
    关注

    You don't need regex for that. str_replace() should work fine:

    $string = 'columns="4" link="file" ids="280,281,282,283,284,285,286,287,288"';
    $replaced = str_replace([' ', '"'], ['&', ''], $string);
    

    Demo: https://3v4l.org/gHHMp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料