我正在使用此函数将文本转换为标题大小写:
function strtotitle($title) {
$smallwordsarray = array( 'of','a','the','and','an','or','nor','but','is','if','then','else','when', 'at','from','by','on','off','for','in','to','into','with','it', 'as' );
// Split the string into separate words
$words = explode(' ', $title);
foreach ($words as $key => $word) {
// If this word is the first, or it's not one of our small words, capitalise it
// with ucwords().
if ($key == 0 or !in_array($word, $smallwordsarray))
$words[$key] = ucwords($word);
}
// Join the words back into a string
$newtitle = implode(' ', $words);
return $newtitle;
}
问题是,如果文本是粗体、斜体等,那么该功能将不起作用,并且不会对单词进行标题。
例如:“这是一个简单的句子”将转换为“这是一个简单的句子”。但是“This is a simple sentence”将转换为“This is a simple Sentence”。
非常感谢任何帮助。