gpt4 book ai didi

php - 在 php 中使用 preg_replace 删除 php 中的空间

转载 作者:行者123 更新时间:2023-12-02 22:35:22 24 4
gpt4 key购买 nike

我有以下字符串 + Example + Test + Test2 并使用 preg_replace 我想得到以下结果 +Example +Test +Test2

我一直在尝试使用下面的代码

preg_replace("/\s*([\+])\s*/", "$1", $string)

但是这个又回来了

+Example+Test+Test2

最佳答案

$output = str_replace('+ ', '+', $input);

$output = preg_replace('/\\+\\s+/', '+', $input);

关于php - 在 php 中使用 preg_replace 删除 php 中的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com