<tfoot id='FLCoa'></tfoot>

<legend id='FLCoa'><style id='FLCoa'><dir id='FLCoa'><q id='FLCoa'></q></dir></style></legend>
  • <i id='FLCoa'><tr id='FLCoa'><dt id='FLCoa'><q id='FLCoa'><span id='FLCoa'><b id='FLCoa'><form id='FLCoa'><ins id='FLCoa'></ins><ul id='FLCoa'></ul><sub id='FLCoa'></sub></form><legend id='FLCoa'></legend><bdo id='FLCoa'><pre id='FLCoa'><center id='FLCoa'></center></pre></bdo></b><th id='FLCoa'></th></span></q></dt></tr></i><div id='FLCoa'><tfoot id='FLCoa'></tfoot><dl id='FLCoa'><fieldset id='FLCoa'></fieldset></dl></div>
      • <bdo id='FLCoa'></bdo><ul id='FLCoa'></ul>

        <small id='FLCoa'></small><noframes id='FLCoa'>

        如何使用正则表达式验证 Twitter 用户名

        时间:2023-09-24

                <bdo id='K8tKt'></bdo><ul id='K8tKt'></ul>

                  <tbody id='K8tKt'></tbody>
                <tfoot id='K8tKt'></tfoot>
              • <legend id='K8tKt'><style id='K8tKt'><dir id='K8tKt'><q id='K8tKt'></q></dir></style></legend>

                <small id='K8tKt'></small><noframes id='K8tKt'>

                <i id='K8tKt'><tr id='K8tKt'><dt id='K8tKt'><q id='K8tKt'><span id='K8tKt'><b id='K8tKt'><form id='K8tKt'><ins id='K8tKt'></ins><ul id='K8tKt'></ul><sub id='K8tKt'></sub></form><legend id='K8tKt'></legend><bdo id='K8tKt'><pre id='K8tKt'><center id='K8tKt'></center></pre></bdo></b><th id='K8tKt'></th></span></q></dt></tr></i><div id='K8tKt'><tfoot id='K8tKt'></tfoot><dl id='K8tKt'><fieldset id='K8tKt'></fieldset></dl></div>
                1. 本文介绍了如何使用正则表达式验证 Twitter 用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在函数中使用了模式 /[a-z0-9_]+/i :

                  I have used the pattern /[a-z0-9_]+/i within the function:

                  function validate_twitter($username) {
                   if (eregi('/[a-z0-9_]+/i', $username)) {
                    return true;
                   }
                  }
                  

                  通过这个,我测试输入是否是有效的 twitter 用户名,但我遇到了困难,因为它没有给我一个有效的结果.

                  With this, I test if the input is a valid twitter username, but i'm having difficulties as it is not giving me a valid result.

                  谁能帮我找到解决办法.

                  Can someone help me find a solution.

                  推荐答案

                  验证字符串是否为有效的 Twitter 句柄:

                  To validate if a string is a valid Twitter handle:

                  function validate_username($username)
                  {
                      return preg_match('/^[A-Za-z0-9_]{1,15}$/', $username);
                  }
                  

                  如果您尝试在字符串中匹配 @username.

                  If you are trying to match @username within a string.

                  例如:RT @username: lorem ipsum @cjoudrey etc...

                  使用以下内容:

                  $string = 'RT @username: lorem ipsum @cjoudrey etc...';
                  preg_match_all('/@([A-Za-z0-9_]{1,15})/', $string, $usernames);
                  print_r($usernames);
                  

                  您可以将后者与 preg_replace_callback 结合使用以链接字符串中的用户名.

                  You can use the latter with preg_replace_callback to linkify usernames in a string.

                  Twitter 还开源文本库用于 Java 和Ruby 用于匹配用户名、哈希标签等.您可以查看代码并找到它们使用的正则表达式模式.

                  Twitter also open sourced text libraries for Java and Ruby for matching usernames, hash tags, etc.. You could probably look into the code and find the regex patterns they use.

                  编辑 (2):这是 Twitter 文本库的 PHP 端口:https://github.com/mzsanford/twitter-text-php#readme

                  Edit (2): Here is a PHP port of the Twitter Text Library: https://github.com/mzsanford/twitter-text-php#readme

                  这篇关于如何使用正则表达式验证 Twitter 用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Twitter OAuth (PHP):需要良好的基本示例才能开始 下一篇:为什么我的 twitter oauth 访问令牌无效/过期

                  相关文章

                  最新文章

                  <tfoot id='HQzk2'></tfoot>
                  1. <small id='HQzk2'></small><noframes id='HQzk2'>

                      <bdo id='HQzk2'></bdo><ul id='HQzk2'></ul>
                    <legend id='HQzk2'><style id='HQzk2'><dir id='HQzk2'><q id='HQzk2'></q></dir></style></legend>

                      <i id='HQzk2'><tr id='HQzk2'><dt id='HQzk2'><q id='HQzk2'><span id='HQzk2'><b id='HQzk2'><form id='HQzk2'><ins id='HQzk2'></ins><ul id='HQzk2'></ul><sub id='HQzk2'></sub></form><legend id='HQzk2'></legend><bdo id='HQzk2'><pre id='HQzk2'><center id='HQzk2'></center></pre></bdo></b><th id='HQzk2'></th></span></q></dt></tr></i><div id='HQzk2'><tfoot id='HQzk2'></tfoot><dl id='HQzk2'><fieldset id='HQzk2'></fieldset></dl></div>