I suggest to use array_reduce. This handles a variable number of values in your $content.
array_reduce takes each value of the array and performs the callback on it. The returned value is then somehow mixed together with the results of the previous content.
In the following code array_reduce takes the initial value 0 as $carray. Then it takes the first element from the $content array (as $text) and adds the length of the $text to the $carray. The result is the new $carray for the next array value. This generates the full length.
$content = '<p>this is p 1</p><p>this is p 2</p><p>this is p 3</p><p>this is p 4</p><p>$test</p>';
$parts = explode('</p>', $content);
$test = array_reduce($parts, function($carry, $text){
return strlen($text) + $carry;
}, 0);
Note that your $content still has the <p> tags which are counted. There are a few ways to count only the text without the tags. The easiest but also least flexible way is to use strip_tags. This will count your text but all tags are removed.
$content = '<p>this is p 1</p><p>this is p 2</p><p>this is p 3</p><p>this is p 4</p><p>$test</p>';
$test = strlen(strip_tags($content));
Another possibility is to remove the <p> tags by e.g. replacing them. I would prefere a regular expression but in exact this case str_replace is enough:
$content = '<p>this is p 1</p><p>this is p 2</p><p>this is p 3</p><p>this is p 4</p><p>$test</p>';
$parts = explode('</p>', $content);
$test = array_reduce($parts, function($carry, $text){
return strlen(str_replace("<p>", "", $text)) + $carry;
}, 0);
Depending on what you need you can also parse your html. This is a lot more powerful but may also be too much:
$content = '<p>this is p 1</p><p>this is p 2</p><p>this is p 3</p><p>this is p 4</p><p>$test</p>';
$dom = new DOMDocument();
$dom->loadHTML("<html><body>".$content."</body></html>");
$test = strlen($dom->textContent);
count_charsreturns an array, as given in the documentation. Have you tried dumping it to inspect the content, such that you see what it returns?explode('</p>',$content)may not give you exactly what you are after, you result will still have the open tags<p>.