Archive for July, 2007

ucsentences

<?php
function ucsentences($str)
{
    return preg_replace_callback('/([^a-z]*)([a-z])(.*?(?:[.:!?]|\Z))/si', 'ucsentences_callback', $str);
}
 
function ucsentences_callback($m)
{
    return $m[1] . strtoupper($m[2]) . $m[3];
}
 
$s = 'the foo, the bar and the baz. something like: what? what! never mind';
echo ucsentences($s);
// The foo, the bar and the baz. Something like: What? What! Never mind
 
?>

Tags: , ,