I'm currently working on a twitter-like mention function, where you can see, if you got mentioned somewhere. You normally can mention someone by writing '@James Hi, what's up' - So I just used
$yourusername = $_SESSION['username'];
$result = $db->query("SELECT * FROM posts WHERE content LIKE '%@".$yourusername."' ORDER by id");
This code is searching for entries containing '@YourUsername'. The problem here is, that it also shows me mentions of @YourUsername2 and @YourUsername3 - I've already tried it by adding spaces, but as you know, people will also do '@James, you ol' bastard :)' or '@James!!!!!'
Edit: This is not my real code, I know how to prevent SQL-injections and that stuff and I'm using it. This is just for keeping the code simple.