Skip to content Skip to sidebar Skip to footer

How To Convert @ Mention Syntax To Html In A Video Game App?

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 anyt

Solution 1:

Javascript

var test = "@[6816:Super Mario Bros.] is a great game! @[6821:Super Mario Bros. 3] is fun too!";
test.replace(/@\[(\d+?):(.+?)\]/g, "<a href=\"/games/$1\">$2</a>");

PHP

$test = '@[6816:Super Mario Bros.] is a great game! @[6821:Super Mario Bros. 3] is fun too!';
preg_replace('/@\[(\d+?):(.+?)\]/', '<a href="/games/$1">$2</a>', $test);

EDIT: Updated to support multiple tags


Post a Comment for "How To Convert @ Mention Syntax To Html In A Video Game App?"