PHP code example of eserozvataf / scabbia2-helpers
1. Go to this page and download the library: Download eserozvataf/scabbia2-helpers 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/ */
eserozvataf / scabbia2-helpers example snippets
use Scabbia\Helpers\Arrays;
$output = Arrays::flat(['a', ['b', 'c']]);
// $output == ['a', 'b', 'c']
$output = Arrays::getFirst(['a', 'b']);
// $output == 'a'
$output = Arrays::get(['a' => '1', 'b' => '2'], 'b');
// $output == '2'
$output = Arrays::getArray(['a' => '1', 'b' => '2', 'c' => '3'], 'a', 'c', 'd');
// $output == ['a' => '1', 'c' => '3', 'd' => null];
$output = Arrays::getPath(['a' => ['b' => ['c' => 5]]], 'a/b/c');
// $output == 5
$output = Arrays::getArrayPath(['a' => ['b' => ['c' => 5, 'd' => 6]]], 'a/b/c', 'a/b/d', 'a/b/e');
// $output == ['a/b/c' => 5, 'a/b/d' => 6, 'a/b/e' => null];
$output = Arrays::getRandom(['a', 'b', 'c']);
// $output == 'c'
$output = Arrays::range(1, 5);
// $output == [1, 2, 3, 4, 5]
$output = Arrays::sortByKey([
['i' => 5],
['i' => 2],
['i' => 4]
], 'i');
// $output == [['i' => 2], ['i' => 4], ['i' => 5]]
$output = Arrays::categorize([
['t' => 'a', 'i' => 5],
['t' => 'b', 'i' => 2],
['t' => 'a', 'i' => 4]
], 't');
// $output == [
// 'a' => [['t' => 'a', 'i' => 5], ['t' => 'a', 'i' => 4]],
// 'b' => [['t' => 'b', 'i' => 2]],
// ]
$output = Arrays::assignKeys([
['i' => 5],
['i' => 2],
['i' => 4]
], 'i');
// $output == [5 => ['i' => 5], 2 => ['i' => 2], 4 => ['i' => 4]]
$output = Arrays::column([
['i' => 5],
['i' => 2],
['i' => 4]
], 'i');
// $output == [5, 2, 4]
$output = Arrays::columns([
['i' => 5, 'j' => 6, 'k' => 7],
['i' => 2, 'j' => 3, 'k' => 4],
['i' => 4, 'j' => 5, 'k' => 6]
], 'i', 'k');
// $output == [
// ['i' => 5, 'k' => 7],
// ['i' => 2, 'k' => 4],
// ['i' => 4, 'k' => 6]
// ]
$output = Arrays::getRow([
['i' => 5, 'j' => 6, 'k' => 7],
['i' => 2, 'j' => 3, 'k' => 4],
['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == ['i' => 5, 'j' => 6, 'k' => 7]
$output = Arrays::getRowKey([
'a' => ['i' => 5, 'j' => 6, 'k' => 7],
'b' => ['i' => 2, 'j' => 3, 'k' => 4],
'c' => ['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == 'a'
$output = Arrays::getRows([
['i' => 5, 'j' => 6, 'k' => 7],
['i' => 2, 'j' => 3, 'k' => 4],
['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == [
// ['i' => 5, 'j' => 6, 'k' => 7],
// ['i' => 5, 'j' => 5, 'k' => 6]
// ]
$output = Arrays::getRowsBut([
['i' => 5, 'j' => 6, 'k' => 7],
['i' => 2, 'j' => 3, 'k' => 4],
['i' => 5, 'j' => 5, 'k' => 6]
], 'i', 5);
// $output == [
// ['i' => 2, 'j' => 3, 'k' => 4]
// ]
$output = Arrays::combine(
['a', 'b', 'c'],
[1, 2]
);
// $output == ['a' => 1, 'b' => 2, 'c' => null]
$output = Arrays::sortByPriority([
'second' => 221,
'forth' => 444,
'third' => 727,
'first' => 878
], ['first', 'second']);
// $output == ['first' => 878, 'second' => 221, 'forth' => 444, 'third' => 727]
use Scabbia\Helpers\String;
$output = String::getEncoding();
// $output == 'utf8'
$output = String::coalesce($_GET['x'], '5');
// $output == '5'
$output = String::prefixLines("line 1\nline 2", '- ');
// $output == "- line 1\n- line 2"
$output = String::filter('1', String::FILTER_SANITIZE_BOOLEAN);
// $output == true
$output = String::format('value: {val}', ['val' => 5]);
// $output == 'value: 5'
String::vardump($_GLOBALS);
// echoes all globals in html format
$output = String::hash('scabbia test');
// $output == <hex encoded strong crc hash>
$output = String::generatePassword(5);
// $output == 'trawr'
$output = String::generateUuid();
// $output == '644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b'
$output = String::generate(6, 'abcdef');
// $output == 'efdabb'
$output = String::xss('<alert="test');
// $output == '<alert="test'
$output = String::strip('eser', 'er');
// $output == 'eer';
$output = String::squote('test\'ed');
// $output == 'test\\\'ed'
$output = String::dquote('scabbia "php" components', true);
// $output == '"scabbia \"php\" components"'
$output = String::replaceBreaks("eser\nozvataf", '<br />');
// $output == 'eser<br />ozvataf'
$output = String::cut('testing', 4, '...');
// $output == 'test...'
$output = String::encodeHtml('<strong>eser & ozvataf</strong>');
// $output == '<strong>eser & ozvataf</strong>'
$output = String::decodeHtml('<strong>eser & ozvataf</strong>');
// $output == '<strong>eser & ozvataf</strong>'
$output = String::toLower('ESER ÖZVATAF');
// $output == 'eser özvataf'
$output = String::toUpper('eser özvataf');
// $output == 'ESER ÖZVATAF'
$output = String::capitalize('eser özvataf');
// $output == 'Eser özvataf'
$output = String::capitalizeWords('eser özvataf');
// $output == 'Eser Özvataf'
$output = String::length('eser özvataf');
// $output == 12
$output = String::startsWith('eser özvataf', 'eser');
// $output == true
$output = String::endsWith('eser özvataf', 'özvataf');
// $output == true
$output = String::substr('eser özvataf', 2, 2);
// $output == 'er'
$output = String::strpos('eser özvataf', 'er');
// $output == 2
$output = String::strstr('[email protected] ', '@');
// $output == '@ozvataf.com'
$output = String::sizeCalc(2048);
// $output == '2K'
$output = String::quantityCalc(5000000);
// $output == '5M'
$output = String::timeCalc(120);
// $output == '2m'
$output = String::removeAccent('eser özvataf');
// $output == 'eser ozvataf'
$output = String::removeInvisibles("eser\0 özvataf");
// $output == 'eser özvataf'
$output = String::slug("eser\0 özvataf");
// $output == 'eser-ozvataf'
$output = String::ordinalize(3);
// $output == '3rd'
$output = String::sanitizeFilename('eser*d.txt');
// $output == 'eser_d.txt'
$output = String::matchPaths(['/src', '/tests'], '\\tests\\notCompleted');
// $output == true
$output = String::convertLinks('my homepage is http://eser.ozvataf.com/', function ($url) { return '[' . $url . '](' . $url . ')'; });
// $output == 'my homepage is [http://eser.ozvataf.com/](http://eser.ozvataf.com/)'