gpt4 book ai didi

php - 正则表达式用空格替换破折号

转载 作者:行者123 更新时间:2023-12-03 23:56:39 25 4
gpt4 key购买 nike

我有一个问题,如何用单个空格替换单个破折号 (-)。

我尝试了以下

$test = TEST-test;
preg_replace('\-', '/s', $test);
echo $test;

但没有结果。

谢谢,

最佳答案

strtr :

$test = strtr($test, '-', ' ');

顺便说一句,你的原始代码是 TEST-test , 需要用引号括起来:
$test = 'TEST-test';

关于php - 正则表达式用空格替换破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11096224/

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