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.