douyu9012 2013-10-23 20:51
浏览 287
已采纳

从字符串中移除加号(+)[复制]

This question already has an answer here:

I am trying to use preg_replace() to remove a plus sign (+) from my string. I used

$variation = preg_replace('/[^\p{L}\p{N}\s]/u', '', $variation);

But that removed periods (.) too, which I need it in the string. Is there a way to just remove the plus sign?

</div>
  • 写回答

3条回答 默认 最新

  • douzha8489 2013-10-23 20:56
    关注

    Although the original answer to this question does achieve the intended effect, it is not the most efficient way to do this simple task. As noted in the comments above, the use of str_replace() is preferred in this case.

    $variation = str_replace("+", "", $variation);
    

    ORIGINAL ANSWER:

    This works to remove only a plus sign:

    $variation = preg_replace(/[+]/, "", $variation);
    

    You can see it work here: http://www.phpliveregex.com/p/1Fb (be sure you select the preg_replace function)

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料