Recommend this page to a friend! |
![]() |
Info | Example | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 102 | All time: 9,786 This week: 206![]() |
Version | License | PHP version | Categories | |||
case-converter 1.0 | Custom (specified... | 5 | PHP 5, Text processing |
Description | Author | |
This package can be used to convert strings between many naming conventions. Innovation Award
|
To use Case Converter you have to instantiate Convert
class, then you
should call to*()
methods.
Code:
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Jawira\CaseConverter\Convert;
$robot = new Convert('The-Terminator');
echo $robot->toPascal() . PHP_EOL;
echo $robot->toCobol() . PHP_EOL;
echo $robot->toSnake() . PHP_EOL;
Output:
TheTerminator
THE-TERMINATOR
the_terminator
In some edge cases you have to explicitly set the format of input string to have the desired output:
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Jawira\CaseConverter\Convert;
$agency = new Convert('FBI');
$agency->fromAda();
echo $agency->toCobol(); // output: FBI
echo $agency->toSnake(); // output: fbi
$agency->fromCamel();
echo $agency->toCobol(); // output: F-B-I
echo $agency->toSnake(); // output: f_b_i
$agency->fromAuto();
echo $agency->toCobol(); // output: FBI
echo $agency->toSnake(); // output: fbi
You can still use _Simple Case-Mapping_ even if you are using PHP 7.3 or newer:
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Jawira\CaseConverter\Convert;
$robot = new Convert('Straße');
$robot->forceSimpleCaseMapping();
echo $robot->toMacro(); // output: STRAßE
[Learn more about Case-Mapping][Case-Mapping].
[CaseConverter factory] is going to instantiate Convert
class for you.
Everything else is the same:
// Convert string to Pascal case
$this->cc->convert('XML')->toPascal(); // Xml
// Convert string to Snake case
$this->cc->convert('v3.0.2')->toSnake(); // v3_0_2
// Convert string to Camel case
$this->cc->convert('first-name')->toCamel(); // firstName
// Convert from Lower case to Dot case
$this->cc->convert('non-SI units')->fromLower()->toDot(); // non-si.units
// Get detected words
$this->cc->convert('Mario Bros')->toArray(); // ['Mario', 'Bros']
// Retrieve original string
$this->cc->convert('use_the_force')->getSource(); // use_the_force
[Case-Mapping]: ./case-mapping.md [CaseConverter factory]: ./using-the-factory.md
Use this library to convert string between:
| Name | Method | Output example |
| ------------- | --------------- | ----------------- |
| ? Camel case | toCamel()
| myNameIsBond
|
| ??? Pascal case | toPascal()
| MyNameIsBond
|
| ? Snake case | toSnake()
| my_name_is_bond
|
| ??? Ada case | toAda()
| My_Name_Is_Bond
|
| ?? Macro case | toMacro()
| MY_NAME_IS_BOND
|
| ? Kebab case | toKebab()
| my-name-is-bond
|
| ? Train case | toTrain()
| My-Name-Is-Bond
|
| ? Cobol case | toCobol()
| MY-NAME-IS-BOND
|
| ? Lower case | toLower()
| my name is bond
|
| ? Upper case | toUpper()
| MY NAME IS BOND
|
| ? Title case | toTitle()
| My Name Is Bond
|
| ?? Sentence case | toSentence()
| My name is bond
|
| ?? Dot notation | toDot()
| my.name.is.bond
|
Features:
Input string (i.e. _john-connor_) format is going to be [detected automatically][detection algorithm]. Here's an example:
use Jawira\CaseConverter\Convert;
$hero = new Convert('john-connor');
echo $hero->toCamel(); // output: johnConnor
Of course you can explicitly set the format of input string:
echo $hero->fromKebab()->toSnake(); // output: john_connor
You can also use the [provided factory][factory] to instantiate Convert
class.
A list of [all public methods] is also available.
Fully compatible with non-english alphabets:
// Spanish
$esp = new Convert('DON_RAMÓN_Y_ÑOÑO');
echo $esp->toCamel(); // output: donRamónYÑoño
// Greek
$grc = new Convert('????-????');
echo $grc->toCamel(); // output: ????????
// Russian
$rus = new Convert('?????_???????');
echo $rus->toCamel(); // output: ????????????
case-converter
is compatible with _Simple Case-Mapping_ and _Full
Case-Mapping_. [Learn more about Case-Mapping][Case-Mapping].
$ composer require jawira/case-converter
<https://jawira.github.io/case-converter/>
If you liked this project, ? star it on [GitHub].
This library is licensed under the [MIT LICENSE].
<!--mkdocs: Do not use relative path for links and images-->
[all public methods]: https://jawira.github.io/case-converter/api.html [CONTRIBUTING.md]: https://jawira.github.io/case-converter/contributing.html [Countable interface]: https://php.net/manual/en/class.countable.php [Case-Mapping]: https://jawira.github.io/case-converter/case-mapping.html [magic method]: https://www.php.net/manual/en/language.oop5.magic.php#object.tostring [MIT LICENSE]: https://jawira.github.io/case-converter/license.html [open an issue]: https://github.com/jawira/case-converter/issues/new [detection algorithm]: https://jawira.github.io/case-converter/detection-algorithm.html [factory]: https://jawira.github.io/case-converter/using-the-factory.html [GitHub]: https://github.com/jawira/case-converter/
*
<dl>
<dt><a href="https://packagist.org/packages/jawira/emoji-catalog">jawira/emoji-catalog</a> (library)</dt> <dd>Get access to +3000 emojis as class constants.</dd>
<dt><a href="https://packagist.org/packages/jawira/phing-visualizer">jawira/phing-visualizer</a> (library)</dt> <dd>Graphical representation of Phing's buildfile.</dd>
<dt><a href="https://packagist.org/packages/jawira/phing-open-task">jawira/phing-open-task</a> (library)</dt> <dd>Phing task to open files, directories, and URLs with your favorite software.</dd>
<dt><a href="https://packagist.org/packages/jawira/">more...</a></dt> </dl>
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation |
![]() |
/ | config |
File | Role | Description |
---|---|---|
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() |
/ | docs |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Example | Example script | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() |
Class | Class source |
![]() |
/ | docs | / | images |
File | Role | Description |
---|---|---|
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() ![]() |
Data | Auxiliary data |
![]() |
/ | src |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
Class | Class source | ||
![]() |
Class | Class source | ||
![]() |
Class | Class source | ||
![]() |
Class | Class source |
![]() |
/ | src | / | Glue |
File | Role | Description |
---|---|---|
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
/ | src | / | Split |
File | Role | Description |
---|---|---|
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
/ | tests | / | behat |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() ![]() |
Data | Auxiliary data |
![]() |
/ | tests | / | phpunit |
File | Role | Description |
---|---|---|
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.