PHP 8.5.0 Alpha 1 available for testing

Voting

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

The Note You're Voting On

jmarois at ca dot ibm dot com
15 years ago
My quick and dirty ucname (Upper Case Name) function.

<?php
//FUNCTION

function ucname($string) {
$string =ucwords(strtolower($string));

foreach (array(
'-', '\'') as $delimiter) {
if (
strpos($string, $delimiter)!==false) {
$string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
}
}
return
$string;
}
?>
<?php
//TEST

$names =array(
'JEAN-LUC PICARD',
'MILES O\'BRIEN',
'WILLIAM RIKER',
'geordi la forge',
'bEvErly CRuSHeR'
);
foreach (
$names as $name) { print ucname("{$name}\n"); }

//PRINTS:
/*
Jean-Luc Picard
Miles O'Brien
William Riker
Geordi La Forge
Beverly Crusher
*/
?>

You can add more delimiters in the for-each loop array if you want to handle more characters.

<< Back to user notes page

To Top