PHP code example of paliari / php-utils
1. Go to this page and download the library: Download paliari/php-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/ */
paliari / php-utils example snippets
$a1 = ['a' => 1];
$a2 = ['b' => ['b1' => 2]];
$a3 = \Paliari\Utils\A::merge($a1, $a2);
var_export($a3);
// export to ['a' => 1, 'b' => ['b1' => 2]]
$val = \Paliari\Utils\A::deepKey($a3, 'b.b1');
var_export($val);
// export to 2;
$flatten = \Paliari\Utils\A::flatten($a3);
var_export($flatten);
// export to [1, 2];
// explode string of space, aliases to explode(' ', $str);
$str = 'a b 1.3d a-x';
$a = w($str);
var_export($a);
// export to ['a', 'b', '1.3d', 'a-x'];
// config custom file log, default is realpath(sys_get_temp_dir()) . '/php-util.log'
$file = __DIR__.'/tmp/logs/test.log';
\Paliari\Utils\Logger::file($file);
//Methods avaliables: "critical, error, warning, notice, info, debug".
// info
\Paliari\Utils\Logger::info('Yor custom message.');
// Init
\Paliari\Utils\CatchFatalError::init();
// Or
\Paliari\Utils\CatchFatalError::init(function ($e) {
// ... custom handler actions, ex: send mail, save custom log...
return $e['message'];
});
// Example
$url = 'https://domain.com/home/?p=1&q[a]=11&q[b]=22#/home';
$u = \Paliari\Utils\Url::parse($url);
var_export($u);
// expected
/*
Paliari\Utils\Url::__set_state(array(
'scheme' => 'https',
'host' => 'domain.com',
'port' => NULL,
'user' => NULL,
'pass' => NULL,
'path' => '/home/',
'query' => 'p=1&q[a]=11&q[b]=22',
'fragment' => '/home',
'url' => 'https://domain.com/home/?p=1&q[a]=11&q[b]=22#/home',
))
*/
// Method queryToArray convert query string to array.
var_export($u->queryToArray());
// expected
/*
array (
'p' => '1',
'q' =>
array (
'a' => '11',
'b' => '22',
),
)
*/