dongti8535 2014-10-11 02:40
浏览 19
已采纳

如何在视频游戏应用中从原始语法中获取@提示标签ID列表?

I'm making a video game app that lets users @ mention a game stored in the database, similar to the way you can @ mention a user on Twitter, or @ mention anything on Facebook.

When the user types '@' when making a comment, JavaScript triggers a drop-down box to appear. The user selects a game from the drop-down box and when he selects it, it goes into the textarea. Each @ mention is stored internally in format @[id-slug:Game Title]. When the user presses "Post", the comment is sent to the server, and the server must process it, to figure out which games were being @ mentioned. An example of the raw text sent to the server would be:

@[6816-nes-super-mario-bros:Super Mario Bros.] is a great game! @[6821-nes-super-mario-bros-3:Super Mario Bros. 3] is fun too!

The server must be able to know which games the user is @ mentioning in his post, so that it can add entries to the comment_game table appropiately, so that these comments also show up on the respective game pages. So in the example above, I need some way to parse this comment to figure out that the user has @ mentioned game IDs 6816 and 6821. Just getting the game IDs will be sufficient for this. Then PHP can know what games the user @ mentioned.

I have tried multiple solutions but none seem to work. I'm not sure if the best solution is to use regular expressions, or another solution.

  • 写回答

1条回答 默认 最新

  • dongyikong6207 2014-10-11 03:08
    关注
    <?php
        $comment = '@[6816-nes-super-mario-bros:Super Mario Bros.] is a great game! @[6821-nes-super-mario-bros-3:Super Mario Bros. 3] is fun too!';
        preg_match_all('/@\[([0-9]+)/', $comment, $users);
        print_r($users);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀