public static function create($str, $camelize = true)
    {
        // remove special chars (accents, etc.)
        $str = trim(self::normalize($str));
        $str = ltrim($str, '#_ ');

        // handle some punctuation and convertable chars
        $find = ["'", "?", "#", "/", "\"", "\\", "&amp;", "&", "%", "@"];
        $repl = ['', '', '', '', '', '', ' And ', ' And ', ' Percent ', ' At '];
        $str = str_replace($find, $repl, $str);

        // replace everything else and split up the words
        $str = preg_replace('/[^a-zA-Z0-9_]/', ':', $str);
        if ($camelize) {
            $str = strtolower(preg_replace('/([A-Z])/', ':$1', $str));
            $str = str_replace(' ', '', ucwords(str_replace(':', ' ', $str)));
        } else {
            $str = str_replace(' ', '', str_replace(':', ' ', $str));
        }

        $str = ltrim($str, '_');
        $hashtag = '';
        $foundLetter = false;
        $len = strlen($str);
        if ($len > 139) {
            return null;
        }

        for ($i = 0; $i < $len; $i++) {
            $char = $str[$i];
            $hashtag .= $char;

            if (!$foundLetter && !is_numeric($char)) {
                $foundLetter = true;
            }
        }

        if (!$foundLetter) {
            return null;
        }

        return empty($hashtag) ? null : $hashtag;
    }
public static function create($str, $camelize = true)
    {
        // remove special chars (accents, etc.)
        $str = trim(self::normalize($str));
        $str = ltrim($str, '#_ ');

        // handle some punctuation and convertable chars
        $find = ["'", "?", "#", "/", "\"", "\\", "&amp;", "&", "%", "@"];
        $repl = ['', '', '', '', '', '', ' And ', ' And ', ' Percent ', ' At '];
        $str = str_replace($find, $repl, $str);

        // replace everything else and split up the words
        $str = preg_replace('/[^a-zA-Z0-9_]/', ':', $str);
        if ($camelize) {
            $str = strtolower(preg_replace('/([A-Z])/', ':$1', $str));
            $str = str_replace(' ', '', ucwords(str_replace(':', ' ', $str)));
        } else {
            $str = str_replace(' ', '', str_replace(':', ' ', $str));
        }

        $str = ltrim($str, '_');
        $hashtag = '';
        $foundLetter = false;
        $len = strlen($str);
        if ($len > 139) {
            return null;
        }

        for ($i = 0; $i < $len; $i++) {
            $char = $str[$i];
            $hashtag .= $char;

            if (!$foundLetter && !is_numeric($char)) {
                $foundLetter = true;
            }
        }

        if (!$foundLetter) {
            return null;
        }

        return empty($hashtag) ? null : $hashtag;
    }
public static function create ( $ str , $ camelize = true ) { // remove special chars (accents, etc.) $ str = trim ( self :: normalize ( $ str ) ) ; $ str = ltrim ( $ str , '#_ ' ) ; // handle some punctuation and convertable chars $ find = [ "'" , "?" , "#" , "/" , "\"" , "\\" , "&amp;" , "&" , "%" , "@" ] ; $ repl = [ '' , '' , '' , '' , '' , '' , ' And ' , ' And ' , ' Percent ' , ' At ' ] ; $ str = str_replace ( $ find , $ repl , $ str ) ; // replace everything else and split up the words $ str = preg_replace ( '/[^a-zA-Z0-9_]/' , ':' , $ str ) ; if ( $ camelize ) { $ str = strtolower ( preg_replace ( '/([A-Z])/' , ':$1' , $ str ) ) ; $ str = str_replace ( ' ' , '' , ucwords ( str_replace ( ':' , ' ' , $ str ) ) ) ; } else { $ str = str_replace ( ' ' , '' , str_replace ( ':' , ' ' , $ str ) ) ; } $ str = ltrim ( $ str , '_' ) ; $ hashtag = '' ; $ foundLetter = false ; $ len = strlen ( $ str ) ; if ( $ len > 139 ) { return null ; } for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ char = $ str [ $ i ] ; $ hashtag .= $ char ; if ( ! $ foundLetter && ! is_numeric ( $ char ) ) { $ foundLetter = true ; } } if ( ! $ foundLetter ) { return null ; } return empty ( $ hashtag ) ? null : $ hashtag ; }
Converts a string into a hash tag.  Hashtag result may be null if it
cannot be converted.

@param string $str
@param bool   $camelize

@return string|null
Converts a string into a hash tag . Hashtag result may be null if it cannot be converted .