Skip to content

Instantly share code, notes, and snippets.

@balsama
Created December 4, 2012 08:12
Show Gist options
  • Save balsama/4201751 to your computer and use it in GitHub Desktop.
Save balsama/4201751 to your computer and use it in GitHub Desktop.
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;
'
),
$string);
return $handles;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment