Created
February 2, 2017 23:45
-
-
Save adactio/efac357d38108cecd8bd52a48f1904f2 to your computer and use it in GitHub Desktop.
A regular expression for turning a word beginning with @ into a link to a Twitter profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = preg_replace( | |
'/(?<=^|\s)@([a-z0-9_]+)/i', | |
'<a href="https://twitter.com/$1">@$1</a>', | |
$string | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment