我正在使用 WordPress 和 WP-O-Matic 自动从不同的提要中提取内容。内容全部大写,使 WordPress 博客中的帖子看起来很糟糕。我尝试使用不同的技术,但它们似乎都没有完美地工作。
以下是我尝试的一些示例:
如何在 php 中将句子中的第一个字母大写 如何将句子中
第一个单词的首字母大写?
我目前正在使用这段代码,但它不能正常工作:
function fwisc_content($content) {
if ( is_single() ) {
global $post;
$string = get_the_content($post->ID);
$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.' ';
}
return trim($new_string);
} else {
return $content;
}
}
add_action( 'the_content', 'fwisc_content' );
问题是这段代码删除了所有<p></p>
标签,使整个帖子看起来像一个段落。
这是我需要做的:
示例输入:
<p>THIS IS THE FIRST SENTENCE. THIS IS THE SECOND SENTENCE! THIS IS THE THIRD SENTENCE.. THIS IS THE FOURTH SENTENCE! IS THIS THE FIFTH SENTENCE?</p>
<p>THIS IS THE FIRST SENTENCE. THIS IS THE SECOND SENTENCE! THIS IS THE THIRD SENTENCE.. THIS IS THE FOURTH SENTENCE! IS THIS THE FIFTH SENTENCE?</p>
预期输出:
<p>This is the first sentence. This is the second sentence! This is the third sentence.. This is the fourth sentence! Is this the fifth sentence?</p>
<p>This is the first sentence. This is the second sentence! This is the third sentence.. This is the fourth sentence! Is this the fifth sentence?</p>
请帮忙