update page now
PHP 8.1.34 Released!

Voting

: eight plus one?
(Example: nine)

The Note You're Voting On

Anonymous
8 years ago
Format the input string:

<?php

function ucsentences($string){
    $parts = preg_split('/([^\.\!\?;]+[\.\!\?;"]+)/', strtolower($string), (-1), PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); 
    $r = '';
    foreach($parts as $key=>$sentence){
        $r .= ucfirst(trim($sentence)) . ' ';
    }
    $r = preg_replace('/\bi\b/', 'I', $r);
    $r = preg_replace_callback('/("[a-z])/', function($m){ return strtoupper($m[0]);}, $r);
    return rtrim($r);
}

$str = 'i\'m not sure. if this is good enough, but i thought: "hey, who know\'s. maybe i am right."';

?>
Outputs:
I'm not sure. If this is good enough, but I thought: "Hey, who know's. Maybe I am right."

<< Back to user notes page

To Top