Hah, that could only work in Italian I think ??
I restructured the foreach loop to accommodate that need. I then noticed my algorithm had problems with dots followed by HTML tags. I fixed it by inserting a space in between. I think the possibility of that insertion being a problem is very rare.
The entire modified code:
function replace_content($content)
{
// Standardize various system newlines as "\n"
$content = str_replace(["\r\n", "\r",], "\n", $content );
// Convert "\n\n" to <br><br> tags
$content = str_replace( "\n\n", ' <br><br>', $content );
// Replace remaining newlines with spaces
$content = str_replace( "\n", ' ', $content );
// Add spaces after dots followed by a HTML tag
$content = str_replace( ".<", '. <', $content );
$parts = explode( '. ', $content );
$w_breaks = '';
$count = 0;
foreach ( $parts as $part ) {
if ( in_array( mb_substr( $part, -1 ), ['a','e','i','o','u',])) {
$glue = ( 3 == $count % 4 )?'.<br>':'. ';
$count++;
} else {
$glue = '. ';
}
$w_breaks .= $part . $glue;
}
// fix trailing dots
$w_breaks = substr( $w_breaks, 0, '. '== $glue? -2: -5 );
return $w_breaks;
}
add_filter('the_content','replace_content');