gpt4 book ai didi

php - 如何在 PHP 中从这个组合中删除点

转载 作者:行者123 更新时间:2023-12-04 02:27:23 25 4
gpt4 key购买 nike

我在一个字符串中有这个组合:

"I am tagging @username1.blah. and @username2.test. and @username3."

我试过这个:

preg_replace('/\@^|(\.+)/', '', 'I am tagging @username1.blah. and @username2.test. and @username3. in my status.');

但结果是:

"I am tagging @username1blah and @username2test and @username3 in my status"

上面的结果不是我想要的

这是我想要实现的:

"I am tagging @username.blah and @username2.test and @username3 in my status."

谁能帮我看看我在模式中做错了什么?

非常感谢,乔恩

最佳答案

我不太喜欢正则表达式,但是当你确定要删除的点后面总是跟一个空格时,你可以这样做:

php > $a = "I am tagging @username1.blah. and @username2.test. and @username3.";
php > echo str_replace(". ", " ", $a." ");
I am tagging @username1.blah and @username2.test and @username3

关于php - 如何在 PHP 中从这个组合中删除点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938255/

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