Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A regular expression for turning a word beginning with @ into a link to a Twitter profile.
<?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
You can’t perform that action at this time.