Skip to content

Latest commit

 

History

History
349 lines (327 loc) · 5.95 KB

README-STR.md

File metadata and controls

349 lines (327 loc) · 5.95 KB

StrTools

This class include specific static functions to make easily string editing

List of content

Static Function

ConvertPersianNumbers

converts persian numbers into english numbers example:

StrTools::ConvertPersianNumbers('۰۱۲۳۴۵۶۷۸۹');

result:

0123456789

ParsCurrentUrl

converts persian numbers into english numbers example:

dd(
    StrTools::ParsCurrentUrl(),
    StrTools::ParsCurrentUrl('www.'),
)

result:

[
    "scheme" => "http",
    "host" => "localhost",
]
[
    "scheme" => "http",
    "host" => "www.localhost",
]

RemoveFileFormat

converts persian numbers into english numbers example:

StrTools::RemoveFileFormat('file_path/file_name.format');

result:

file_path/file_name

GetGuardName

Returns user guard name by guard type (see config).

example:

StrTools::GetGuardName('web');

result:

user

GetLangAttribute

Returns translated word by attribute part of validation.php language file.

example in validation.php:

'attributes' => [
    // other attribute 
    'username' => 'user name'
],

example GetLangAttribute function:

StrTools::GetLangAttribute('username');

result:

user name

RemoveEmptyExplode

Removes empty string between separator.

example:

StrTools::RemoveEmptyExplode(',','val1, val2, val3,,,');

result:

val1, val2, val3

IsEmptyString

Detect empty chars (see config)

example:

$isEmptyStr1 = StrTools::IsEmptyString('');
$isEmptyStr2 = StrTools::IsEmptyString(''); // half space
$isEmptyStr3 = StrTools::IsEmptyString('value');
$isEmptyStr3 = StrTools::IsEmptyString('‌value'); // with half space
dd($isEmptyStr1,$isEmptyStr2,$isEmptyStr3);

result:

true
true
false

RandomInt

Returns random integer.

example:

$isEmptyStr1 = StrTools::RandomInt(16);

result:

2246770845368407

GetFirst

Returns first char of string.

example:

dd(
    StrTools::GetFirst('value'),
    StrTools::GetFirst('value',2),
)

result:

v
va

AutoChangeWord

Replace same words. (see config)

example:

StrTools::AutoChangeWord('درود خوبي');

result:

StrTools::AutoChangeWord('درود خوبی');

JustNumber

Check if value just have number or not. (see config wrong_numbers and persian_numbers)

example:

$value = '12345۶۷۸۹';
dd(
    StrTools::JustNumber($value),
    StrTools::JustNumber($value.'value'),
    StrTools::JustNumber($value,false),
);

result:

true
false
false

JustPhoneNumber

Check if value just have number and 11 chars or not. (see config wrong_numbers and persian_numbers)

example:

$value = '09120000۰۰۰';

dd(
    StrTools::JustPhoneNumber($value),
    StrTools::JustPhoneNumber($value,false)
);

result:

true
false

GetFileFormat

Returns file extension by file name

example:

StrTools::GetFileFormat('directory\file_name.txt');

result:

txt

DetectCssProps

Returns CSS props from text to array.

example:

StrTools::DetectCssProps('width: 28px; height: 1rem');

result:

[
    "width" => "28px",
    "height" => "1rem",
]

RepairNumber

Returns replaced correct number characters.

example:

StrTools::RepairNumber('09120000۰۰۰');

result:

09120000000

RemoveLast

Returns value without last character(s).

example:

dd(
    StrTools::RemoveLast('value'),
    StrTools::RemoveLast('value',2)
);

result:

valu
val

RemoveFirst

Returns value without first character(s).

example:

dd(
    StrTools::RemoveFirst('value'),
    StrTools::RemoveFirst('value',2)
);

result:

alue
lue

ConvertToUrlParams

Returns url query params from array.

example:

$params = [
    'key1' => 'value1',
    'key2' => 'value2',
];
StrTools::ConvertToUrlParams($params);

result:

?key1=value1&key2=value2

RepairPhoneNumber

Returns value without any space and country code and replaces persian numbers.

example:

StrTools::RepairPhoneNumber('+989120000000');

result:

09120000000

GetPhoneCode

Returns code of phone number

example:

StrTools::GetPhoneCode('+989120000000');

result:

[
    "name" => "Iran (+98)",
    "code" => "98",
]

HaveInFirst

Returns code of phone number.

example:

StrTools::HaveInFirst('value 1', 'val');

result:

true

StrContainsArray

Check if string contain in array or not

example:

dd(
    StrTools::StrContainsArray('test 1',['test']),
    StrTools::StrContainsArray('test 1',['test 2'])
)

result:

true
false

StrEqualArray

Check if string contain in array or not

example:

dd(
    StrTools::StrEqualArray('test 1',['test 1']),
    StrTools::StrEqualArray('test 1',['test'])
)

result:

true
false