https://github.com/katmore/case-convert
case coversion library
https://github.com/katmore/case-convert
Last synced: 14 days ago
JSON representation
case coversion library
- Host: GitHub
- URL: https://github.com/katmore/case-convert
- Owner: katmore
- License: mit
- Created: 2018-09-07T20:45:57.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T03:19:27.000Z (almost 8 years ago)
- Last Synced: 2025-10-28T21:43:45.264Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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()`](https://php.net/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()`](https://php.net/ucwords)
```php
echo ucwords("i am the other one");
/* --output--
I Am The Other One
*/
```
#### INCORRECT title casing with `mb_convert_case()`
The [`mb_convert_case()`](https://php.net/mb_convert_case) function, part of the [*mbstring* extension](https://php.net/manual/en/ref.mbstring.php), produces the same identically incorrect results as [`ucwords()`](https://php.net/ucwords).
```php
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`](https://php.net/manual/en/class.intlbreakiterator.php) of the [*intl* extension](https://php.net/manual/en/book.intl.php) 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()`](https://php.net/ucwords)).
```php
$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](https://github.com/katmore/case-convert/blob/master/LICENSE) and [GPLv3](https://github.com/katmore/case-convert/blob/master/GPLv3).