hiroto-k/string-builder

String builder class for PHP.

1.1.0 2022-08-06 05:29 UTC

This package is auto-updated.

Last update: 2024-05-06 09:19:06 UTC


README

PHP from Packagist License

String builder class for PHP.

<?php

$str = 'Your String';

// Normal PHP.
// Display 'MY STRING'.
echo mb_strtoupper(str_replace('Your', 'My', $str), 'utf-8');

// Using this library.
// Display 'MY STRING'.
use HirotoK\StringBuilder\StringBuilder;

echo StringBuilder::make($str)->replace('Your', 'My')->upcase();

Requirements

  • PHP 7.0 or later
  • mbstring extension

Installation

1, Download this library

Modify require directive in composer.json.

{
  "require": {
    "hiroto-k/string-builder": "1.*"
  }
}

OR

$ composer require hiroto-k/php-string-builder

2, Load vendor/autoload.php file

Load vendor/autoload.php in your codes.

3, Use StringBuilder class

<?php

// Load composer packages.
require "vendor/autoload.php";

// Using StringBuilder class.
use HirotoK\StringBuilder\StringBuilder;

// Create StringBuilder object.
$sb = new StringBuilder('Your string');

// Alias of '__construct'.
// This method is useful to method chain.
$sb = StringBuilder::make('Your string');

License

MIT License