Skip to content

Instantly share code, notes, and snippets.

@balsama
balsama / twitter-un-filter.php
Created December 4, 2012 08:12
Function to convert all valid twitter usernames into links to their twitter page.
<?php
function twitter_un_filter($string) {
$handles = preg_replace_callback('/@([A-Za-z0-9_]+)/',
create_function(
'$handles',
'
$username = substr($handles[0], 1);
$handles = "<a href=\"https://twitter.com/" . $username . "\" class=\"twitter-un-filter-link\">" . $handles[0] . "</a>";
return $handles;
'