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); 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); } 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. Link to comment https://forums.phpfreaks.com/topic/232725-twitter-like-profile-linking/#findComment-1197022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.