Created
August 22, 2019 06:31
-
-
Save andreconghau/556323cb51cb1ba98d1b3f5468a33f6a to your computer and use it in GitHub Desktop.
get HashTag
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 | |
function convertAll($str) { | |
$regex = "/[@#](\w+)/"; | |
$hrefs = [ | |
'#' => 'hashtag?tag', | |
'@' => 'profile?username' | |
]; | |
$result = preg_replace_callback($regex, function($matches) use ($hrefs) { | |
return sprintf( | |
'<a href="%s=%s">%s</a>', | |
$hrefs[$matches[0][0]], | |
$matches[1], | |
$matches[0] | |
); | |
}, $str); | |
return($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment