Voting

: seven plus zero?
(Example: nine)

The Note You're Voting On

octavius
15 years ago
For lithuanian text with utf-8 encoding I use two functions (thanks [mattalexxpub at gmail dot com] and Svetoslav Marinov)

<?php
function my_ucfirst($string, $e ='utf-8') {
if (
function_exists('mb_strtoupper') && function_exists('mb_substr') && !empty($string)) {
$string = mb_strtolower($string, $e);
$upper = mb_strtoupper($string, $e);
preg_match('#(.)#us', $upper, $matches);
$string = $matches[1] . mb_substr($string, 1, mb_strlen($string, $e), $e);
}
else {
$string = ucfirst($string);
}
return
$string;
}

function
sentence_case($string) {
$sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
$new_string = '';
foreach (
$sentences as $key => $sentence) {
$new_string .= ($key & 1) == 0?
my_ucfirst(strtolower(trim($sentence))) :
$sentence.' ';
}
return
trim($new_string);
}
?>

<< Back to user notes page

To Top