doddsey_65 Posted April 5, 2011 Share Posted April 5, 2011 im trying to link a profile if it is prefixed with an @ symbol. I have tried this but it doesnt work as i thought it wouldnt. $content = preg_replace('|@(.*?)|', profile_link('$1'), $content); Quote Link to comment https://forums.phpfreaks.com/topic/232725-twitter-like-profile-linking/ Share on other sites More sharing options...
kartul Posted April 5, 2011 Share Posted April 5, 2011 function at_name($content) { $pattern = '/\@([a-zA-Z0-9._-]+)/'; $replace = '<a href="'. BASE_URL . 'u/\1">@\1</a> '; return preg_replace($pattern, $replace, $content); } Quote Link to comment https://forums.phpfreaks.com/topic/232725-twitter-like-profile-linking/#findComment-1197020 Share on other sites More sharing options...
SamT_ Posted April 5, 2011 Share Posted April 5, 2011 echo preg_replace("#\@([a-z0-9\_]+)#i", '<a href="http://www.twitter.com/$1">@$1</a>', $text); You can replace the twitter.com with anything, such as your function that generates the URL. Quote Link to comment https://forums.phpfreaks.com/topic/232725-twitter-like-profile-linking/#findComment-1197022 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.