2017 © Pedro Peláez
 

library string-converter

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

image

sebastiansulinski/string-converter

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  • Tuesday, November 14, 2017
  • by sebastiansulinski
  • Repository
  • 1 Watchers
  • 5 Stars
  • 7,305 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 15 % Grown

The README.md

Simple string converter

This package allows converting between different string formats., (*1)

Usage examples

Class-name

use SSD\StringConverter\Factory;


echo Factory::classNameToCamel('PhpEol');
// phpEol

echo Factory::classNameToConstant('PhpEol');
// PHP_EOL

echo Factory::classNameToHyphen('PhpEol');
// Php-Eol

echo Factory::classNameToUnderscore('PhpEol');
// Php_Eol

echo Factory::classNameToSpace('PhpEol');
// Php Eol

Camel-case

use SSD\StringConverter\Factory;


echo Factory::camelToClassName('phpEol');
// PhpEol

echo Factory::camelToConstant('phpEol');
// PHP_EOL

echo Factory::camelToHyphen('phpEol');
// php-Eol

echo Factory::camelToUnderscore('phpEol');
// php_Eol

echo Factory::camelToSpace('phpEol');
// php Eol

Constant

use SSD\StringConverter\Factory;


echo Factory::constantToClassName('PHP_EOL');
// PhpEol

echo Factory::constantToCamel('PHP_EOL');
// phpEol

echo Factory::constantToHyphen('PHP_EOL');
// PHP-EOL

echo Factory::constantToUnderscore('PHP_EOL');
// PHP_EOL

echo Factory::constantToSpace('PHP_EOL');
// PHP EOL

Hyphen

use SSD\StringConverter\Factory;


echo Factory::hyphenToClassName('php-eol');
// PhpEol

echo Factory::hyphenToCamel('php-eol');
// phpEol

echo Factory::hyphenToConstant('php-eol');
// PHP_EOL

echo Factory::hyphenToUnderscore('php-eol');
// php_eol

echo Factory::hyphenToSpace('php-eol');
// php eol

Underscore

use SSD\StringConverter\Factory;


echo Factory::underscoreToClassName('php_eol');
// PhpEol

echo Factory::underscoreToCamel('php_eol');
// phpEol

echo Factory::underscoreToConstant('php_eol');
// PHP_EOL

echo Factory::underscoreToHyphen('php_eol');
// php-eol

echo Factory::underscoreToSpace('php_eol');
// php eol

Space

use SSD\StringConverter\Factory;


echo Factory::spaceToClassName('php eol');
// PhpEol

echo Factory::spaceToCamel('php eol');
// phpEol

echo Factory::spaceToConstant('php eol');
// PHP_EOL

echo Factory::spaceToHyphen('php eol');
// php-eol

echo Factory::spaceToUnderscore('php eol');
// php_eol

Optional second callback argument

Factory methods can take an optional, second argument of callable type so you can additionally modify the result:, (*2)

echo Factory::constantToSpace('PHP_EOL');
// PHP EOL

echo Factory::constantToSpace('PHP_EOL', 'strtolower');
// php eol

echo Factory::constantToSpace('PHP_EOL', function($string) {
    return str_replace(' ', '', $string);
});
// phpeol

The Versions

14/11 2017

dev-master

9999999-dev

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Sebastian Sulinski

14/11 2017

v2.1.0

2.1.0.0

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Sebastian Sulinski

31/07 2016

v2.0.1

2.0.1.0

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Sebastian Sulinski

29/06 2016

v2.0.0

2.0.0.0

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Sebastian Sulinski

20/04 2015

1.1.0

1.1.0.0

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Sebastian Sulinski

01/03 2015

1.0.0

1.0.0.0

Convert between snake and camel case, hyphen to camel case, to constant name, ucfirst, ucwords

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Sebastian Sulinski