|
@@ 284-294 (lines=11) @@
|
| 281 |
|
* @param string $strEncoding Encoding of text |
| 282 |
|
* @return int |
| 283 |
|
*/ |
| 284 |
|
public static function wordCount($strText, $strEncoding = '') |
| 285 |
|
{ |
| 286 |
|
if (strlen(trim($strText)) == 0) { |
| 287 |
|
return 0; |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
// Will be tripped by em dashes with spaces either side, among other similar characters |
| 291 |
|
$intWords = 1 + self::textLength(preg_replace('`[^ ]`', '', preg_replace('`\s+`', ' ', $strText)), $strEncoding); // Space count + 1 is word count |
| 292 |
|
|
| 293 |
|
return $intWords; |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
/** |
| 297 |
|
* Returns sentence count for text. |
|
@@ 302-312 (lines=11) @@
|
| 299 |
|
* @param string $strEncoding Encoding of text |
| 300 |
|
* @return int |
| 301 |
|
*/ |
| 302 |
|
public static function sentenceCount($strText, $strEncoding = '') |
| 303 |
|
{ |
| 304 |
|
if (strlen(trim($strText)) == 0) { |
| 305 |
|
return 0; |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
// Will be tripped up by "Mr." or "U.K.". Not a major concern at this point. |
| 309 |
|
$intSentences = max(1, self::textLength(preg_replace('`[^\.!?]`', '', $strText), $strEncoding)); |
| 310 |
|
|
| 311 |
|
return $intSentences; |
| 312 |
|
} |
| 313 |
|
|
| 314 |
|
/** |
| 315 |
|
* Returns average words per sentence for text. |