Split Words on Specific Characters (PHP)
This snippet requires the JS counterpart gpppw-split-words-on-specific-characters.js
Code
Filename: gpppw-split-words-on-specific-characters.php
<?php
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (PHP)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the JS counterpart gpppw-split-words-on-specific-characters.js
*/
add_filter( 'gpppw_word_count', function( $word_count, $words ) {
// Splits words on periods, underscores and asterisks.
$words = preg_replace( '/[\.\_\*]/', ' ', $words );
return count( array_filter( preg_split( '/[ \n\r]+/', trim( $words ) ) ) );
}, 10, 2 );