mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 23:28:14 +01:00
16 lines
297 B
PHP
16 lines
297 B
PHP
<?php
|
|
|
|
/**
|
|
* This is a simple way to count sentence
|
|
* using php preg_match_all() function
|
|
*
|
|
* @param string $sentence
|
|
* @return int
|
|
*/
|
|
function countSentences(string $sentence): int
|
|
{
|
|
$sentence = trim($sentence);
|
|
|
|
return preg_match_all('/[^\s|^\...](\.|\!|\?)(?!\w)/', $sentence);
|
|
}
|