PHP code example of commandstring / utils
1. Go to this page and download the library: Download commandstring/utils library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
commandstring / utils example snippets
toStdClass(array $array): stdClass
$users = [
"value" => [
"users" => [
[
"username" => "user",
"password" => "********",
"email" => "[email protected] "
]
]
],
"token" => "********************************"
];
$users = ArrayUtils::toStdClass($users);
var_dump($users);
/* output
object(stdClass)#2 (2) {
["value"]=>
object(stdClass)#4 (1) {
["users"]=>
object(stdClass)#5 (1) {
["0"]=>
object(stdClass)#6 (3) {
["username"]=>
string(4) "user"
["password"]=>
string(8) "********"
["email"]=>
string(16) "[email protected] "
}
}
}
["token"]=>
string(32) "********************************"
}
*/
randomize(array $array): array
$characters = str_split("Command_String");
$randomized_characters = ArrayUtils::randomize($characters);
foreach ($randomized_characters as $character) {
echo $character;
}
getBetween(string $start, string $end, string $string, bool $
$greeting = "My name is Bob! What's yours?";
$name = StringUtils::getBetween("is ", "!", $greeting);
echo $name; // output: Bob
$text = 'fdsjhyasdfuygfdsuygfduygfsd{"name": "Bob"}asduygasduyauysduytasduy?';
$json = StringUtils::getBetween("{", "}", $text, true);
echo $json; // output: {"name": "Bob"}
var_dump(json_decode($json));
/* output:
object(stdClass)#3 (1) {
["name"]=>
string(5) "Bob"
}
*/
uuid(int $length = 16, array $characters = []): string
echo GeneratorUtils::uuid(); // output: 6MwqCff0wdpUl1sdw
echo GeneratorUtils::uuid(5); // output: 8zWgWw
echo GeneratorUtils::uuid(10, [1, 0]); // output: 11110100100
getAllFiles(string $directory, bool $recursive = false): array
getAllSubDirectories(string $directory, bool $recursive = false): array
getAllFilesWithExtensions(string $directory, array $extensionsToFind, bool $recursive = false): array
RGBAtoHEX(int $red, int $blue, int $green, ?int $alpha = null): string
HEXtoRGBA(string $hex): array
convertFileSize(FileSizeUtils $from_type, FileSizeUtils $to_type, float $from_size): float
humanReadable(FileSizeUtils $type, float $size, int $decimals = 0): string
echo FileSizeUtils::humanReadable(FileSizeUtils::MEGABYTE, 5000); // output: 5 GB
reduceFileSize(FileSizeUtils $type, float $size): stdClass
var_dump(FileSizeUtils::humanReadable(FileSizeUtils::MEGABYTE, 5000));
/**
* object(stdClass)#12 (2) {
* ["type"]=>
* enum(CommandString\Utils\FileSizeUtils::GIGABYTE)
* ["size"]=>
* float(5)
* }
*/