I am using WordPress and WP-O-Matic to automatically pull contents from different feeds. The contents are in all caps making the posts in the WordPress blog looks crappy. I tried using different techniques, but none of them seem to work flawlessly.
Here are some examples I tried:
How to uppercase the first letter in a sentence in php
How to capitalize first letter of first word in a sentence?
I am currently using this piece of code, but its not working like it should:
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' );
The problem is this code removes all the <p></p>
tags making the whole post looks like a single paragraph.
Here is what I need to do:
Sample Input:
<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>
Expected Output:
<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>
Please help