我在句子情況下使用了格式化函數。我的PHP腳本功能是使用函數進行字符串大小寫轉換
function sentence_case($string) {
$sentences = preg_split(
'/([.?!]+)/',
$string,
-1,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
);
$new_string = '';
foreach ($sentences as $key => $sentence) {
$new_string .= ($key & 1) == 0
? ucfirst(strtolower(trim($sentence)))
: $sentence . ' ';
}
$new_string = preg_replace("/\bi\b/", "I", $new_string);
//$new_string = preg_replace("/\bi\'\b/", "I'", $new_string);
$new_string = clean_spaces($new_string);
$new_string = m_r_e_s($new_string);
return trim($new_string);
}
雖然它的進行得很好,並且將整個字符串轉換成了句子。但我希望它能在單引號中跳過字符。像我的字符串HeLLO world! HOw aRE You.
正在轉換爲Hello world! How are you?
,但我想跳過單引號中的內容。就像我希望在單引號中跳過單詞一樣。 'HELLO' World
並將單引號中的單詞轉換爲大寫,否則字符串應保留在句子大小寫中。
只是單挑:你會遇到各種各樣的麻煩與專有名詞。 –
我知道我的英語很差... –
我不認爲他的意思是說你的英語不好,但應該把大寫的專有名詞。 –