Skip to content

katmore/case-convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2ebc02c · Sep 8, 2018

History

18 Commits
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018
Sep 8, 2018

Repository files navigation

case-convert - ALPHA (NOT READY)

case coversion library

Title Casing

The title casing problem in PHP

PHP does not have any convenient "built-in" means of converting a text string value to "title case" format (also known as "proper case"). The few candidate functions in official PHP extensions do not properly adhere to any known English style guide for title casing. In fact, as demonstrated below, they do nothing different than the ucwords() function!

Take the example of the phrase i am the other one, which SHOULD be I am the Other One when properly title cased.

INCORRECT title casing with ucwords()

echo ucwords("i am the other one");
/* --output--
I Am The Other One
*/

INCORRECT title casing with mb_convert_case()

The mb_convert_case() function, part of the mbstring extension, produces the same identically incorrect results as ucwords().

echo mb_convert_case("i am the other one",MB_CASE_TITLE);
/* --output--
I Am The Other One
*/

INCORRECT title casing with IntlBreakIterator::createTitleInstance()

The IntlBreakIterator of the intl extension disapoints as well. Besides offering an absurdly tedious to interface to apply to this purpose, it ultimately provides incorrect results when using the IntlBreakIterator::createTitleInstance() method (identical to using ucwords()).

$text = "i am the other one";
$titleIterator = IntlBreakIterator::createTitleInstance("en-US");
$titleIterator->setText($text);
foreach($titleIterator as $boundary) {
        if (strlen($text)-1<$boundary) break 1;
        $text[$boundary] = strtoupper($text[$boundary]);
}
echo $text;
/* --output--
I Am The Other One
*/

Legal

Copyright

https://github.com/katmore/case-convert

Copyright (c) 2018 D. Bird. All Rights Reserved.

License

Case-convert is copyrighted free software. You may redistribute and modify it under either the terms and conditions of the "The MIT License (MIT)"; or the terms and conditions of the "GPL v3 License". See LICENSE and GPLv3.

About

case coversion library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages