Skip to content

Instantly share code, notes, and snippets.

@02Tea
Created July 22, 2017 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 02Tea/4e74e6d1142c3bc126ac9783f3157524 to your computer and use it in GitHub Desktop.
Save 02Tea/4e74e6d1142c3bc126ac9783f3157524 to your computer and use it in GitHub Desktop.
[String to Hashtag] #php #peg #exnc
/**
* 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