我知道要替换我可以使用的空格:
str_replace(' ', ';', $string);
Run Code Online (Sandbox Code Playgroud)
我的问题是......我如何只更换第一个空间?
例如:firstword secondword thirdword到firstword;secondword thirdword
我会使用 preg_replace
$subject='firstword secondword thirdword';
$result = preg_replace('%^([^ ]+?)( )(.*)$%', '\1;\3', $subject);
var_dump($result);
Run Code Online (Sandbox Code Playgroud)