用href链接替换匹配的文本



我有一个字符串,比如:

@test hello how are you @abcdef

我该如何自动制作它,以便它将所有带有@的文本转换为类似的内容

https://example.com/test
https://example.com/abcdef

我尝试过使用regex和preg_replace,但无法完全恢复。

尝试使用替换https://example.com/$1:的regex@(S+)

$string = '@test hello how are you @abcdef';
$result = preg_replace('/@(S+)/', 'https://example.com/$1', $string);
print($result);

最新更新