Download the PHP package torugo/tstring without Composer
On this page you can find all versions of the php package torugo/tstring. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download torugo/tstring
More information about torugo/tstring
Files in torugo/tstring
Package tstring
Short Description Toolset for validating and manipulating strings.
License MIT
Informations about the package tstring
TString
Small toolset for validating and handling strings.
Inspired on validator.js.
Table of Contents
- Requirements
- Installation
- Usage
- Via Traits
- Via TString static object
- Validators
- contains
- isAlpha
- isAlphanumeric
- isBase64
- isCnpj
- isCpf
- IsEmail
- IsHexadecimal
- isLength
- isNumeric
- isSemVer
- isUrl
- UrlOptions
- maxLength
- minLength
- maxVersion
- minVersion
- Handlers
- toString
- toLowerCase
- toTitleCase
- toUpperCase
- Contribute
- License
Requirements
- PHP 8+
- PHP mbstring extension installed and loaded.
- Composer 2+
Installation
Usage
You can use this library in two ways, using specific Traits or instantiating the TString class.
Via Traits
Traits are a good way to use only the functions you need, just use them within your classes.
[!NOTE] All valitors and manipulators traits functions visibility are
protected static
.
Via TString static object
TString class is the easiest way to use the functions of this library, by using it you will have access to all features in a single object.
Validators
contains
Checks if a substring is contained in another string.
[!NOTE] By default the case sensitiveness is enabled.
Trait Namespace
Examples
isAlpha
Validates if a string have only alphabetical characters.
[!NOTE] When enabled, the argument
$includeUnicode
will include some unicode alphabetic characters like accented letters, and alphabetical characters from some languages. This option is disabled by default.
Trait Namespace
Examples
isAlphanumeric
Validates if a string have only alphanumeric characters.
[!NOTE] When enabled, the argument
$includeUnicode
will include some unicode alphabetic characters like accented letters, and alphabetical characters from some languages. This option is disabled by default.
Trait Namespace
Examples
isBase64
Validates whether a string is in Base64 format.
Also validates url safe Base64 strings.
Trait Namespace
Examples
isCnpj
Validates if a given string has a valid CNPJ registration.
The Brazil National Registry of Legal Entities number (CNPJ) is a company identification number that must be obtained from the Department of Federal Revenue(Secretaria da Receita Federal do Brasil) prior to the start of any business activities.
Trait Namespace
Examples
[!NOTE] This validator uses a validation code from Guilherme Sehn.
[!IMPORTANT] The cnpj numbers above were generated randomly using this tool.
If one of them belongs to you, please send me a request to remove.
isCpf
Validates if a given string has a valid CPF identification.
CPF Stands for “Cadastro de Pessoas Físicas” or “Registry of Individuals”. It is similar to the “Social Security” number adopted in the US, and it is used as a type of universal identifier in Brazil.
Trait Namespace
Examples
[!NOTE] This validator uses a validation code from Rafael Neri.
[!IMPORTANT] The CPF numbers above were generated randomly using this tool.
If one of them belongs to you, please send me a request and I will remove it immediately.
IsEmail
Validates if a string has a valid email structure.
Trait Namespace
Examples
[!TIP] Take a look at the tests to see more of valid or invalid e-mails.
IsHexadecimal
Validates if a string is a hexadecimal number.
Trait Namespace
Examples
isLength
Validates if the length of a string is between the minimum and maximum parameters.
[!IMPORTANT] If
$min
is negative it will be setted to0
(zero).
If$max
is lesser than1
it will be setted to1
.
If$min
is lesser than$max
, their values will be swapped.
Trait Namespace
Examples
isNumeric
Validates if a string have only numeric characters.
Trait Namespace
Examples
isSemVer
Trait Namespace
Examples
isUrl
Validates if a string have only numeric characters.
[!NOTE] This validator is based on validator.js
Trait Namespace
Examples
UrlOptions
Default values:
maxLength
Validates if the length of a string is lesser than or equal to a maximum parameter.
Trait Namespace
Examples
minLength
Validates if the length of a string is greater than or equal to a minimum parameter.
Trait Namespace
Examples
maxVersion
Checks if a version number is lesser or equal to a given one.
This function validates version numbers that have only numbers sepatared by periods.
- Valid: '8.3.8', '5.0', '3.22.2', '10', '126.0.6478.63' ...
- Invalid: '2.0.0-rc.1', '1.0.0-beta' ...
Trait Namespace
Examples
minVersion
Checks if a version is greater or equal to a given one.
This function validates version numbers that have only numbers sepatared by periods.
- Valid: '8.3.8', '5.0', '3.22.2', '10', '126.0.6478.63' ...
- Invalid: '2.0.0-rc.1', '1.0.0-beta' ...
Trait Namespace
Examples
Handlers
toString
Tries to convert some types to string.
Types supported | Notes |
---|---|
integer |
Simple int to string convertion |
double |
Simple double to string convertion |
boolean |
Returns 'true' or 'false' string values |
array |
Implodes elements with an empty ('' ) separator by default |
object |
Checks if object implements __toString() method, otherwise returns false |
resource |
Tries to get the outup stream, returns false in case of fail |
NULL |
Returns an empty string ('' ) |
[!NOTE] Returns a
string
when succeed, andfalse
on fail.
The$arraySeparator
is used only when the value's type is 'array'.
Trait Namespace
Examples
toLowerCase
Changes the case of a string to lowercase.
Trait Namespace
Examples
toTitleCase
Changes the case of a string to title case, with options to fix Roman numerals and Portuguese language prepositions.
[!NOTE] The arguments
$fixRomanNumerals
and$fixPortuguesePrepositions
are disabled by default.
Trait Namespace
Examples
toUpperCase
Changes the case of a string to uppercase.
Trait Namespace
Examples
Contribute
It is currently not open to contributions, I intend to make it available as soon as possible.
License
This library is licensed under the MIT License - see the LICENSE file for details.
All versions of tstring with dependencies
ext-mbstring Version *