This class include specific static functions to make easily string editing
- StrTools
- List of content
- Static Function
- ConvertPersianNumbers
- ParsCurrentUrl
- RemoveFileFormat
- GetGuardName
- GetLangAttribute
- RemoveEmptyExplode
- IsEmptyString
- RandomInt
- GetFirst
- AutoChangeWord
- JustNumber
- JustPhoneNumber
- GetFileFormat
- DetectCssProps
- RepairNumber
- RemoveLast
- RemoveFirst
- ConvertToUrlParams
- RepairPhoneNumber
- GetPhoneCode
- HaveInFirst
- StrContainsArray
- StrEqualArray
converts persian numbers into english numbers example:
StrTools::ConvertPersianNumbers('۰۱۲۳۴۵۶۷۸۹');
result:
0123456789
converts persian numbers into english numbers example:
dd(
StrTools::ParsCurrentUrl(),
StrTools::ParsCurrentUrl('www.'),
)
result:
[
"scheme" => "http",
"host" => "localhost",
]
[
"scheme" => "http",
"host" => "www.localhost",
]
converts persian numbers into english numbers example:
StrTools::RemoveFileFormat('file_path/file_name.format');
result:
file_path/file_name
Returns user guard name by guard type (see config).
example:
StrTools::GetGuardName('web');
result:
user
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
Removes empty string between separator.
example:
StrTools::RemoveEmptyExplode(',','val1, val2, val3,,,');
result:
val1, val2, val3
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
Returns random integer.
example:
$isEmptyStr1 = StrTools::RandomInt(16);
result:
2246770845368407
Returns first char of string.
example:
dd(
StrTools::GetFirst('value'),
StrTools::GetFirst('value',2),
)
result:
v
va
Replace same words. (see config)
example:
StrTools::AutoChangeWord('درود خوبي');
result:
StrTools::AutoChangeWord('درود خوبی');
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
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
Returns file extension by file name
example:
StrTools::GetFileFormat('directory\file_name.txt');
result:
txt
Returns CSS props from text to array.
example:
StrTools::DetectCssProps('width: 28px; height: 1rem');
result:
[
"width" => "28px",
"height" => "1rem",
]
Returns replaced correct number characters.
example:
StrTools::RepairNumber('09120000۰۰۰');
result:
09120000000
Returns value without last character(s).
example:
dd(
StrTools::RemoveLast('value'),
StrTools::RemoveLast('value',2)
);
result:
valu
val
Returns value without first character(s).
example:
dd(
StrTools::RemoveFirst('value'),
StrTools::RemoveFirst('value',2)
);
result:
alue
lue
Returns url query params from array.
example:
$params = [
'key1' => 'value1',
'key2' => 'value2',
];
StrTools::ConvertToUrlParams($params);
result:
?key1=value1&key2=value2
Returns value without any space and country code and replaces persian numbers.
example:
StrTools::RepairPhoneNumber('+989120000000');
result:
09120000000
Returns code of phone number
example:
StrTools::GetPhoneCode('+989120000000');
result:
[
"name" => "Iran (+98)",
"code" => "98",
]
Returns code of phone number.
example:
StrTools::HaveInFirst('value 1', 'val');
result:
true
Check if string contain in array or not
example:
dd(
StrTools::StrContainsArray('test 1',['test']),
StrTools::StrContainsArray('test 1',['test 2'])
)
result:
true
false
Check if string contain in array or not
example:
dd(
StrTools::StrEqualArray('test 1',['test 1']),
StrTools::StrEqualArray('test 1',['test'])
)
result:
true
false