A regular expression to convert @@ usernames into hyperlinks
This file contains 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 | |
/* Pass a string of text into the function to convert @@ usernames. */ | |
function autoLinkMastodonUsernames($string) { | |
return preg_replace( | |
'/@?\b([A-Za-zŽžÀ-ÿ0-9._%+-]+)@([A-Za-zŽžÀ-ÿ0-9.-]+\.[A-Za-zŽžÀ-ÿ]{2,})\b/i', | |
'<a href="https://$2/@$1">$0</a>', | |
$string | |
); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment