Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13144047
StringUtilities.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
StringUtilities.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Strings\Multibyte
;
class
StringUtilities
{
/**
* Pads a multibyte string to a certain length with another string
*
* @param string $input the input string
* @param int $padLength the target string size
* @param string $padString the padding characters (optional, default is space)
* @param int $padType STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH (optional, default is STR_PAD_RIGHT)
* @param string $encoding the character encoding (optional)
*
* @return string the padded string
*
*/
public
static
function
pad
(
string
$input
,
int
$padLength
,
string
$padString
=
' '
,
int
$padType
=
STR_PAD_RIGHT
,
string
$encoding
=
''
)
:
string
{
return
(
new
StringPad
)
->
setInput
(
$input
)
->
setPadLength
(
$padLength
)
->
setPadString
(
$padString
)
->
setPadType
(
$padType
)
->
setEncoding
(
$encoding
?:
mb_internal_encoding
())
->
pad
();
}
public
static
function
isSupportedEncoding
(
string
$encoding
)
:
bool
{
foreach
(
mb_list_encodings
()
as
$supportedEncoding
)
{
if
(
$encoding
===
$supportedEncoding
)
{
return
true
;
}
}
return
false
;
}
public
static
function
startsWith
(
string
$string
,
string
$start
)
{
$length
=
mb_strlen
(
$start
);
return
mb_substr
(
$string
,
0
,
$length
)
===
$start
;
}
public
static
function
endsWith
(
string
$string
,
string
$end
)
{
$length
=
mb_strlen
(
$end
);
return
$length
===
0
||
mb_substr
(
$string
,
-
$length
)
===
$end
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 16:55 (16 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3176876
Default Alt Text
StringUtilities.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment