I am using this code to split my content after the first punctuation mark, retrieving the fist sentence.
$content = preg_split('/(?<=[!?.])./', $content);
How can I remove that remaining punctuation mark at the end of the splitted sentence?
I am using this code to split my content after the first punctuation mark, retrieving the fist sentence.
$content = preg_split('/(?<=[!?.])./', $content);
How can I remove that remaining punctuation mark at the end of the splitted sentence?
you can run after this
$content = ltrim($content, '.');
or
$content = str_replace('.', '', $content);
You can use:
$content = substr($content, 0, -1);
This will remove the last character from $content.
try dis code!
$test   =   'Ho! My! God!';
    $temp   =   split('!',trim($test,'!'));
    echo "=".__LINE__."=><pre>";print_r($temp);echo "</pre>";
    Array
(
    [0] => Ho
    [1] =>  My
    [2] =>  God
)
How about:
$content = "Hello, world! What's new today? Everything's OK.";
$arr = preg_split('/[!?.] ?/', $content, -1, PREG_SPLIT_NO_EMPTY);
print_r($arr);
This splits on punctuation mark !?. followed by an optionnal space.  The captured strings don't contain leading space.
The difference with yours is that I don't catch the punctuation.
output:
Array
(
    [0] => Hello, world
    [1] => What's new today
    [2] => Everything's OK
)