Created
July 22, 2017 12:32
-
-
Save 02Tea/4e74e6d1142c3bc126ac9783f3157524 to your computer and use it in GitHub Desktop.
[String to Hashtag] #php #peg #exnc
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
/** | |
* conver string to hastag | |
* @param string $string string you want to convert | |
* @param boolean $with_hashtag if false, it won't return the # sign | |
* @return string Eureka! you got your #hashtag! | |
*/ | |
function stringToHashtag($string, $with_hashtag = true) | |
{ | |
$_string = str_replace(' ', '', $string); | |
$_out = preg_replace('/[^a-zA-Z]/', '', strtolower($_string)); | |
return ($with_hashtag) ? "#". $_out : $_out ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment