PHPverse 2025

Voting

: max(four, zero)?
(Example: nine)

The Note You're Voting On

adefoor at gmail dot com
17 years ago
Ken and zee

One thing I would do to make this more unviersally work would be to add strtolower() around your $sentence. Doing this will allow you to convert an all caps text block as well as an all lowercase text block.

<?php

function sentence_cap($impexp, $sentence_split) {
$textbad=explode($impexp, $sentence_split);
$newtext = array();
foreach (
$textbad as $sentence) {
$sentencegood=ucfirst(strtolower($sentence));
$newtext[] = $sentencegood;
}
$textgood = implode($impexp, $newtext);
return
$textgood;
}

$text = "this is a sentence. this is another sentence! this is the fourth sentence? no, this is the fourth sentence.";
$text = sentence_cap(". ",$text);
$text = sentence_cap("! ",$text);
$text = sentence_cap("? ",$text);

echo
$text; // This is a sentence. This is another sentence! This is the fourth sentence? No, this is the fourth sentence.

?>

<< Back to user notes page

To Top