faybe Posted August 15, 2010 Share Posted August 15, 2010 Hey, What i want is that if a username inserts some text into a field like "Hey @martin how are ya" ? then it will display @martin as a link that takes you to site.com/martin, i searched php.net from preg_replace and str_replace...unfortunately for me things got so complicated that i don't even want to talk about it. Anyone who can do it will be my saviour! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 You wont find an exact example of what you're trying to achive within the manual. But you are looking at the right functions to use, which was preg_replace. You'll need to use regex to convet @username to a clickable to link which takes them to the uses profile. Example code $str = 'Hello, @martin How are you?'; $str = preg_replace('~@([a-z0-9]+)~i', '<a href="http://site.com/$1">@$1</a>', $str); echo $str; Quote Link to comment Share on other sites More sharing options...
faybe Posted August 15, 2010 Author Share Posted August 15, 2010 Dude, that was exactly what i meant. Woohoo, your awesome. Thanks. I will put it on my brainHDD so i wont have to ask this again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.