Created
March 22, 2018 23:54
-
-
Save jongacnik/7477b34926699352cfcb49376aa1736d to your computer and use it in GitHub Desktop.
Extract first sentence from text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function firstsentence($string) { | |
$parts = preg_split('/(^.*?[a-zA-Z0-9\)\”\"]{2,}[.!?])[\s\”\"]+\W*[A-Z]/', strip_tags($string), -1, PREG_SPLIT_DELIM_CAPTURE); | |
$parts = array_values(array_filter($parts)); | |
return (is_array($parts) && isset($parts[0])) ? $parts[0] : $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment