使用 @ 符号来识别用户,就像 twitter 一样

编程入门 行业动态 更新时间:2024-10-23 17:24:04
本文介绍了使用 @ 符号来识别用户,就像 twitter 一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在创建我自己的 twitter 版本,我不知道如何让我的后端 php 脚本在输入的文本中选择 @membername.包括多个@membername,例如@billy @joseph、@tyrone、@kesha 消息

I'm creating my own version of twitter, I have no idea how to get my back end php script to pick up the @membername within the entered text. Including multiple @membername's for example @billy @joseph, @tyrone,@kesha message

@billy 与 @tyrone 联系,他向 @kesha 询问你欠他的钱.

@billy hit up @tyrone he's bugging @kesha about the money you owe him.

关于如何完成此操作的任何使用脚本?

Any scripts of use on how I can accomplish this?

推荐答案

如何使用正则表达式和 preg_match_all,像这样:

What about using a regex and preg_match_all, like this :

$str = "Including multiple @membername's for example @billy @joseph, @tyrone,@kesha message ";
if (preg_match_all('#(@\w+)#', $str, $m)) {
    var_dump($m[1]);
}


这会给你以下输出:


Which would give you the following output :

array
  0 => string '@membername' (length=11)
  1 => string '@billy' (length=6)
  2 => string '@joseph' (length=7)
  3 => string '@tyrone' (length=7)
  4 => string '@kesha' (length=6)


基本上,在这里,我在正则表达式中使用的模式是匹配的:


Basically, here, the pattern I used in my regex is matching :

一个 @ 字符任何(多个) 可以在单词中的字符:\w+关于此,请参阅 反斜杠 页面,在PHP 手册的正则表达式(Perl 兼容) 部分 An @ character Any (more than one) character that can be inside a word : \w+ About that, see the Backslash page, in the Regular Expressions (Perl-Compatible) section of the PHP manual

这篇关于使用 @ 符号来识别用户,就像 twitter 一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 16:05:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1192099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:就像   符号   用户   twitter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!