Skip to main content
simplified the code
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Just count the spaces and add 1:

// No need to count markup.
$text        = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( $text"$text ", ' ' ) + 1;;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', $text"$text ", $m ) + 1;;

Just count the spaces and add 1:

// No need to count markup.
$text        = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( $text, ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', $text, $m ) + 1;

Just count the spaces and add 1:

// No need to count markup.
$text        = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( "$text ", ' ' );

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', "$text ", $m );
Added strip_tags().
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Just count the spaces and add 1:

$word_number// No need to count markup.
$text        = substr_counttrim( trimstrip_tags( get_the_content() ) );
$word_number = substr_count( $text, ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', trim( get_the_content() )$text, $m ) + 1;

Just count the spaces and add 1:

$word_number = substr_count( trim( get_the_content() ), ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', trim( get_the_content() ), $m ) + 1;

Just count the spaces and add 1:

// No need to count markup.
$text        = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( $text, ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', $text, $m ) + 1;
A second approach with preg_match_all().
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Just count the spaces and add 1:

$word_number = substr_count( trim( get_the_content() ), ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', trim( get_the_content() ), $m ) + 1;

Just count the spaces and add 1:

$word_number = substr_count( get_the_content(), ' ' ) + 1;

Just count the spaces and add 1:

$word_number = substr_count( trim( get_the_content() ), ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', trim( get_the_content() ), $m ) + 1;
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459
Loading