我需要一些幫助功能,我有這樣的代碼大寫每個單詞的第一個字符的字符串例外,我需要的功能,忽略了的異常,如果它是在字符串的開頭:ucwords有例外
function ucwordss($str, $exceptions) {
$out = "";
foreach (explode(" ", $str) as $word) {
$out .= (!in_array($word, $exceptions)) ? strtoupper($word{0}) . substr($word, 1) . " " : $word . " ";
}
return rtrim($out);
}
$string = "my cat is going to the vet";
$ignore = array("is", "to", "the");
echo ucwordss($string, $ignore);
// Prints: My Cat is Going to the Vet
這就是即時通訊做:
$string = "my cat is going to the vet";
$ignore = array("my", "is", "to", "the");
echo ucwordss($string, $ignore);
// Prints: my Cat is Going to the Vet
// NEED TO PRINT: My Cat is Going to the Vet
順便說一句,你可以使用ucfirst而不是'strtoupper($ word {0})。 substr($ word,1)' – RiaD 2012-08-16 22:53:43