I'm making a video game app that lets users @ mention a video game that is stored in the database. It works similar to the way you can @ mention users 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. Internally, the string is stored using the format @[id:Game Title], which is a format I made up. So, if I want to @ mention "Super Mario Bros." in a comment I am making, the string stored internally (and sent to the database) would be:
@[6816:Super Mario Bros.] is a great game!
This format allows the application to know that the game ID is 6816, and that the game is "Super Mario Bros.".
When the comment displayed later, it needs to be in HTML format so that the user can click on the link to the game if he/she wants to. How would I use PHP to convert this raw string into HTML format, such as:
<a href="/games/6816">Super Mario Bros.</a> is a great game!
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. Keep in mind that a user can @ mention as many games as he/she so desires!