Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

LitGroup/str.php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String utils for PHP 7

String utils for PHP.

Version License Downloads Build Status

Installation

composer require litgroup/str:^0.2.1

Example of usage

UTF-8 String Manipulation

There is the class Str, which contains collection of methods for string manipulation. This methods use mb_string internally, but you should'n be worried of encoding. Str methods always work with the UTF-8 encoding.

<?php

use LitGroup\Str\Str;

Str::length('hello'); // => 5
Str::isEmpty('hello'); // => false
Str::isNotEmpty('hello'); // => true
Str::trim(' hello '); // => 'hello'
// ...

Check the code to see all methods.

Using Patterns

From time to time you need to check that a string matches to the pattern. For this purpose, this library provides the Pattern interface. RegExp is one implementation of Pattern, which represents Perl-Compatible Regular Expressions (PCRE).

<?php

use LitGroup\Str\RegExp;

$emailPattern = new RegExp('/^\w+(?:[-+.\']\w+)*@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*$/Dsu');

if ($emailPattern->isSatisfiedBy('[email protected]')) {
    echo 'This is a valid email address!';
}