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! Link to comment https://forums.phpfreaks.com/topic/210782-how-to-make-username-to-a-link/ 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; Link to comment https://forums.phpfreaks.com/topic/210782-how-to-make-username-to-a-link/#findComment-1099539 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. Link to comment https://forums.phpfreaks.com/topic/210782-how-to-make-username-to-a-link/#findComment-1099541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.