2017 © Pedro Peláez
 

library string-builder

A string builder library providing different string methods written in PHP.

image

markenwerk/string-builder

A string builder library providing different string methods written in PHP.

  • Thursday, January 4, 2018
  • by bonscho
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,156 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 11 Versions
  • 24 % Grown

The README.md

PHP String Builder

Build Status Test Coverage Dependency Status SensioLabs Insight Code Climate Latest Stable Version Total Downloads License, (*1)

A basic string builder library providing different string methods written in PHP., (*2)

Installation

```{json} { "require": { "chroma-x/string-builder": "~1.0" } }, (*3)


## Usage ### Autoloading and namesapce ```{php} require_once('path/to/vendor/autoload.php');

Building and modifying a string

```{php} use ChromaX\StringBuilder\StringBuilder;, (*4)

$builder = new StringBuilder('rolod muspi meroL'); $builder ->reverse() ->append(' sit amet, consetetur') ->append(12) ->append(false) ->prepend('b') ->append(true) ->insert(1, 'qäs') ->replace(6, 2, 'wertz') ->setCharAt(4, '2') ->delete(0, 2) ->delete(40) ->deleteCharAt(3);, (*5)

$result = $builder->build(); fwrite(STDOUT, ' 1. Built string ' . $result . PHP_EOL);, (*6)

$result = $builder->buildSubstring(5, 2); fwrite(STDOUT, ' 2. Built substring ' . $result . PHP_EOL);, (*7)

$result = $builder->buildSubstring(5); fwrite(STDOUT, ' 3. Built substring ' . $result . PHP_EOL);, (*8)

$result = $builder->charAt(5); fwrite(STDOUT, ' 4. Character at position 5 ' . $result . PHP_EOL);, (*9)

$result = $builder->firstChar(); fwrite(STDOUT, ' 5. First character ' . $result . PHP_EOL);, (*10)

$result = $builder->lastChar(); fwrite(STDOUT, ' 6. Last character ' . $result . PHP_EOL);, (*11)


will output the following ```{txt} 1. Built string ä2wertzem ipsum dolor sit amet, conset 2. Built substring rt 3. Built substring rtzem ipsum dolor sit amet, conset 4. Character at position 5 r 5. First character ä 6. Last character t

Getting string properties

```{php} $result = $builder->length(); fwrite(STDOUT, ' 7. String length ' . $result . PHP_EOL);, (*12)

$result = $builder->size(); fwrite(STDOUT, ' 8. Number of bytes ' . $result . PHP_EOL);, (*13)

$result = $builder->indexOf('e'); fwrite(STDOUT, ' 9. First occurence of "e" ' . $result . PHP_EOL);, (*14)

$result = $builder->indexOf('e', 5); fwrite(STDOUT, '10. First occurence of "e" after position 5 ' . $result . PHP_EOL);, (*15)

$result = $builder->lastIndexOf('e'); fwrite(STDOUT, '11. Last occurence of "e" ' . $result . PHP_EOL);, (*16)

$result = $builder->lastIndexOf('e', 5); fwrite(STDOUT, '12. Last occurence of "e" before the 5th last character ' . $result . PHP_EOL);, (*17)

$result = $builder->contains('ipsum'); fwrite(STDOUT, '13. Whether the string contains "ipsum" ' . $result . PHP_EOL);, (*18)


will output the following ```{txt} 7. String length 38 8. Number of bytes 39 9. First occurence of "e" 4 10. First occurence of "e" after position 5 8 11. Last occurence of "e" 37 12. Last occurence of "e" before the 5th last character 29 13. Whether the string contains "ipsum" <TRUE>

Exception handling

All methods throw an \InvalidArgumentException if misconfigured except indexOf and lastIndexOf wich return null if the given subtring is not contained by the string to build., (*19)

```{php} use ChromaX\StringBuilder\StringBuilder;, (*20)

try { $builder = new StringBuilder();, (*21)

$result = $builder->indexOf('a');
fwrite(STDOUT, '1. Result                 ' . $result . PHP_EOL);

$result = $builder->lastIndexOf('a');
fwrite(STDOUT, '2. Result                 ' . $result . PHP_EOL);

$result = $builder->charAt(10);
fwrite(STDOUT, '3. Result                 ' . $result . PHP_EOL);

} catch (\InvalidArgumentException $exception) { fwrite(STDERR, 'Exception with message ' . $exception->getMessage() . PHP_EOL); }, (*22)


will output the following ```{txt} 1. Result <NULL> 2. Result <NULL> Exception with message Position invalid

Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document., (*23)

License

PHP String Builder is under the MIT license., (*24)

The Versions

04/01 2018

dev-master

9999999-dev http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

04/01 2018

1.0.10

1.0.10.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

03/01 2018

1.0.9

1.0.9.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

03/01 2018

1.0.7

1.0.7.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

03/01 2018

1.0.6

1.0.6.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

30/08 2016

1.0.5

1.0.5.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

string builder

30/08 2016

1.0.4

1.0.4.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

string builder

12/08 2016

1.0.3

1.0.3.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

string builder

12/08 2016

1.0.2

1.0.2.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

string builder

12/08 2016

1.0.1

1.0.1.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

string builder

09/08 2016

1.0.0

1.0.0.0 http://markenwerk.net/

A string builder library providing different string methods written in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

string builder