PHPString
PHP String wrapper class and methods., (*1)
Installation
Use composer
Type this command., (*2)
composer require hota1024/php-string, (*3)
Can't you use composer?
OK., (*4)
- Download this repository.
- Extract the PHPString-master.zip.
- You can use
PHPString-master/src/hota1024/String.php
How to use it?
composer
require_once "path/to/vendor/autoload.php";
$str = new hota1024\Str('Hello world!');
echo $str; # Hello world!
Don't use composer
include "path/to/String.php";
$str = new hota1024\Str('Hello world!');
echo $str; # Hello world!
Tutorial
Step1「Create String object」
$string = new hota1024\Str('string value'); # Create string object.
Troublesome coding hota1024\Str?, (*5)
You can use this code., (*6)
use \hota1024\Str;, (*7)
use \hota1024\Str;
$string = new hota1024\Str('string value');
Step2「Output string value」
Usually use echo., (*8)
$helloworld = new Str('Hello world!');
echo $helloworld; # Hello world!
If you wish objective programming code?, (*9)
You can use this method., (*10)
$helloworld = new Str('Hello world!');
$helloworld->output(); # Hello world!
Step3「String to Array」
$helloworld = new Str('Hello world!');
var_dump($helloworld->asArray()); # Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => w [7] => o [8] => r [9] => l [10] => d [11] => ! )
Step4「Reverse string」
You can make reverse string., (*11)
$apple = new Str('Apple');
$apple->reverse();
echo $apple; # elppA
You wish reversed value?, (*12)
$apple = new Str('Apple');
$rev = $apple->reversed();
echo $rev; # elppA
Step4.1「Write compact code」
$apple = new Str('Apple');
$apple->reverse();
echo $apple; # elppA
↓, (*13)
$apple = new Str('Apple');
$apple->reverse()->output(); # elppA