You can use this function wp_strip_all_tags
.
strlen( wp_strip_all_tags($post->post_content));
With that you get rid of all the HTML tags.
Just a little extra detail, you might want to strip the shortcodes, too. You can use this function strip_shortcodes
You will end up with something like this:
strlen( wp_strip_all_tags(strip_shortcodes($post->post_content)));
To convert the encoded entities to the corresponding string value you could use the PHP function html_entity_decode
.
Example.
" " </S<>;
is converted to
" " </S<>;
TEST:
//CODE
var_dump($post->post_content);
var_dump(wp_strip_all_tags($post->post_content, true));
var_dump(html_entity_decode(wp_strip_all_tags($post->post_content, true)));
var_dump(html_entity_decode(strip_shortcodes(wp_strip_all_tags($post->post_content, true))));
//RESULTS
string 'áé´r´díó' ñ " " </S<>; a
' (length=59)
string 'áé´r´díó' ñ " " </S<>; a ' (length=56)
string 'áé´r´díó' ñ " " </S<>; a ' (length=47)
string 'áé´r´díó' ñ " " </S<>; a ' (length=38)
//CODE
var_dump(strlen(html_entity_decode(strip_shortcodes(wp_strip_all_tags($post->post_content, true)))));
var_dump(strlen(html_entity_decode(wp_strip_all_tags($post->post_content, true))));
var_dump(strlen(wp_strip_all_tags($post->post_content, true)));
//RESULTS
int 38
int 47
int 56
As I was using var_dump
each string has it’s lenght, but I added the results of the call to the strlen
function anyway.