<?php
function hashtag($text) {
$text = preg_replace('/(?<!\S\W\w)#([0-9a-zA-Z]+)/', '<a href="https://twitter.com/hashtag/$1?src=hash" target="_blank" rel="nofollow">#$1</a>', $text);
return preg_replace('/(?<!\S\W\w)@([0-9a-zA-Z]+)/', '<a href="https://twitter.com/$1" target="_blank" rel="nofollow">@$1</a>', $text);
}
/* using */
$text = "Journalist @NYT - open source supporter • Web developer & Graphic designer | #freelancer #coder #news";
echo hashtag($text);