PHP code example of 86dev / php-tools

1. Go to this page and download the library: Download 86dev/php-tools 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/ */

    

86dev / php-tools example snippets


BoolHelper::to_bool('yes'); // true
BoolHelper::to_bool('true'); // true
BoolHelper::to_bool(1); // true
BoolHelper::to_bool(1.5); // true

BoolHelper::to_bool('no'); // false
BoolHelper::to_bool('false'); // false
BoolHelper::to_bool(0); // false
BoolHelper::to_bool(null); // false

// You can use it to parse user input
BoolHelper::to_bool($_GET['user_input']);

// Or check a parameter
function test($param)
{
	$param = BoolHelper::to_bool($param);
}

$value = "Some string with MANY Words";
StringHelper::split_words($value); // ['Some', 'string', 'with', 'MANY', 'Words']
StringHelper::capitalize($value); // Some string with many words
StringHelper::pascal_case($value); // SomeStringWithManyWords
StringHelper::camel_case($value); // someStringWithManyWords
StringHelper::snake_case($value); // some_string_with_many_words
StringHelper::upper_snake_case($value); // SOME_STRING_WITH_MANY_WORDS
StringHelper::capital_snake_case($value); // Some_String_With_Many_Words
StringHelper::kebab_case($value); // some-string-with-many-words
StringHelper::train_case($value); // Some-String-With-Many-Words
StringHelper::initial($value); // SSWMW

ServerArray::REQUEST_URI();

HtmlCodes::OK; // 200
HtmlCodes::UNAUTHORIZED; // 401
HtmlCodes::FORBIDDEN; // 403
HtmlCodes::NOT_FOUND; // 404
HtmlCodes::IM_A_TEAPOT; // 418
...

$timer = new Timer(true); // true to automatically start the timer

a_long_function();
$first_duration = $timer->duration(); // returns the time in seconds with milliseconds since the timer has been started until now

another_long_function();
$timer->stop(); // stops the timer
$final_duration = $timer->duration(); // returns the time since the timer has been started until it has been stopped.

a_third_long_function();
// calling $timer->duration() now will return the time since the timer has been started until it has been stopped, so the same as $final_duration.

echo $final_duration; // ex: 75.547682
echo $timer; // print m:ss.zzz, ex: 1:15.548

$timers = new Timers();
$timers->start('all');

$timers->start('first');
a_long_function();
$timers->stop('first');

$timers->start('second');
another_long_function();
$timers->stop('second');

$timers->start('third');
a_third_long_function();
$timers->stop('third');

$timers->stop('all');

echo $timers->get('first');
echo $timers->get('second');
echo $timers->get('third');
echo $timers->get('all');

$logger = new Monolog\Logger('Test');
$logger->pushProcessor(new TimerProcessor());

$logger = new Monolog\Logger('Test');
$logger->pushProcessor(new RequestIdProcessor());