If I do this:
$comments = str_replace( "\n\n", "\n", $comments );
And this:
$comments = explode( "\n", $comments );
Then in a loop, how could this…
if( strlen( $comments[ $i ] ) == 0 )
…possibly be true???
There’s not really any more context to it, it’s pretty straight forward and I’m a long time PHP developer, this is really stumping me.
P.S. I’ve also tried something like…
$comments = str_replace( "\n\n\n", "\n", $comments );
$comments = str_replace( "\n\n", "\n", $comments );
$comments = str_replace( "\n\n", "\n", $comments );
…in succession and I still get the same issue.
Several other answers have pointed out the possibility of more than two adjacent line breaks.
Another easy way for an empty string to be part of the
explodeoutput would be an input string with a line break at the end:(this would also happen if it’s
"\n\n"there)Running that through your code gives you the following array: