23 lines
472 B
PHP
23 lines
472 B
PHP
<?php
|
|
|
|
function hashtag($str,$ucfirst=true) {
|
|
$str=preg_replace('#^\W*(.*)\W*$#u','$1',$str);
|
|
$str=preg_split('#\W+#u',$str);
|
|
$c=count($str);
|
|
if ($c>1) {
|
|
($ucfirst) ? $beg=0 : $beg=1;
|
|
for ($i=$beg; $i<$c; $i++) {
|
|
if (preg_match('#^.#u',$str[$i],$matches)===1) {
|
|
$first=mb_strtoupper($matches[0],'UTF-8');
|
|
$str[$i]=preg_replace('#^.#u',$first,$str[$i]);
|
|
}
|
|
}
|
|
$str=implode('',$str);
|
|
} else {
|
|
$str=$str[0];
|
|
}
|
|
$str="#{$str}";
|
|
return $str;
|
|
}
|
|
|
|
?>
|