PHP code example of vielhuber / stringhelper
1. Go to this page and download the library: Download vielhuber/stringhelper 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' );
vielhuber / stringhelper example snippets
if (__x($var)) {
}
if (__x(@$var)) {
}
if (__nx($var)) {
}
if (__nx(@$var)) {
}
if (__rx($var)) {
}
if (__fx(fn() => $var)) {
}
if (__rnx($var)) {
}
if (__fnx(fn() => $var)) {
}
if ( 0 == 'true' )
if ( 0 == 'str' )
if ( 'null' == null )
if ( '0' == null )
if ( '0' == true )
if ( '0' == false )
if ( 'false' == true )
if ( 'false' == false )
if ( new stdClass == true )
if ( [] == false )
if ( [] == null )
if ( ['' ] == [] )
if ( ['' ] == [0 ] )
if ( 0 == '' )
if ( 0 == ' ' )
if ( -1 == true )
if ( '-1' == true )
$a = '' ; $b = 0 ; $c = 'oh' ;
$a == $b;
$b == $c;
$c == $a;
if ( $var === 'foo' )
{
}
if ( $_GET['number' ] == 1337 )
{
}
if ( __true($var) )
{
}
if ( __false($var) )
{
}
__true(null )
__false(null )
__v( $var )
__v( $var, 'default' )
__v( $var1, $var2, $var3 )
__e( $var )
__e( $var, 'default' )
__e( $var1, $var2, $var3 )
foreach (__e($array) as $array__key => $array__value) {
}
if ( __x(@$var) )
if ( __nx(@$var) )
if ( __true(@$var) )
if ( __false(@$var) )
if ( @$var === 'foo' )
if ( @$_GET['number' ] == 1337 )
echo __v(@$var)
foreach ( __e(@$array) as $array__key=>$array__value)
__fx(fn()=>$var)
__fx(fn()=>$var['foo' ]['bar' ]['baz' ])
__fx(fn()=>$var())
__fx(function () use (&$var) {
return $var['foo' ]['bar' ]['baz' ];
});
__rx($var)
__rx($var['foo' ]['bar' ]['baz' ])
__nrx($var)
array_key_exists('foo' , get_defined_vars());
__rx($foo);
array_key_exists('foo' , get_defined_vars());
class Person
{
public $id;
function __construct ($id)
{
$this ->id = $id;
}
static function find ($id)
{
if ( $id === 1 || $id === 2 )
{
return new Person($id);
}
else
{
return null ;
}
}
function getAddress ()
{
if ( $this ->id === 1 )
{
return new Address();
}
else
{
return null ;
}
}
}
class Address
{
function getCountry ()
{
return new Country();
}
}
class Country
{
function getName ()
{
return 'Germany' ;
}
}
echo Person::find(1 )->getAddress()->getCountry()->getName();
echo Person::find(2 )->getAddress()->getCountry()->getName();
echo Person::find(3 )->getAddress()->getCountry()->getName();
echo Person::find(3 )?->getAddress()?->getCountry()?->getName();
class Person
{
public $id;
function __construct ($id)
{
$this ->id = $id;
}
static function find ($id)
{
if ( $id === 1 || $id === 2 )
{
return new Person($id);
}
else
{
return __empty();
}
}
function getAddress ()
{
if ( $this ->id === 1 )
{
return new Address();
}
else
{
return __empty();
}
}
}
class Address
{
function getCountry ()
{
return new Country();
}
}
class Country
{
function getName ()
{
return 'Germany' ;
}
}
__empty()
echo Person::find(1 )->getAddress()->getCountry()->getName();
echo Person::find(2 )->getAddress()->getCountry()->getName();
echo Person::find(3 )->getAddress()->getCountry()->getName();
if ( __x(Person::find(1 )->getAddress()->getCountry()->getName()) )
{
}
if ( Person::find(1 )->getAddress()->getCountry()->getName() === 'Germany' )
{
}
echo __v( Person::find(1 )->getAddress()->getCountry()->getName(), 'default' );
foreach ( Person::find(1 )->getAddress()->getCountry() as $value )
{
}
if ( __x_all('foo' , 'bar' , null ) )
if ( __x_all(['foo' , 'bar' , null ]) )
if ( __x_all('foo' , 'bar' , 'baz' ) )
if ( __x_all(['foo' , 'bar' , 'baz' ]) )
if ( __nx_all('foo' , 'bar' , null ) )
if ( __nx_all('foo' , 'bar' , 'baz' ) )
if ( __x_one('foo' , 'bar' ) )
if ( __x_one('' , null ) )
if ( __x_one(['foo' , 'bar' ]) )
if ( __x_one(['' , null ]) )
if ( __nx_one('foo' , 'bar' ) )
if ( __nx_one('' , null ) )
if ( __true_all(true , true , true ) )
if ( __true_all([true , true , null ]) )
if ( __true_all(true , '1' ) )
if ( __true_all([true , false ]) )
if ( __false_all('foo' , 'bar' , null ) )
if ( __false_all(false ) )
if ( __true_one(true , true , true ) )
if ( __true_one([true , true , null ]) )
if ( __true_one(true , '1' ) )
if ( __true_one([true , false ]) )
if ( __false_one('foo' , 'bar' , null ) )
if ( __false_one(false ) )
__cookie_set('cookie_name' , 'cookie_value' )
__cookie_set('cookie_name' , 'cookie_value' , 7 )
__cookie_set('cookie_name2' , ['can also' , 'store' , 'arrays' ], 7 )
__cookie_set('cookie_name3' , 'cookie_value' , 7 , [
'path' => '/' ,
'domain' => '' ,
'samesite' => 'None' ,
'secure' => true ,
'httponly' => false
])
__cookie_exists('cookie_name' )
__cookie_get('cookie_name' )
__cookie_get('cookie_name2' )
__cookie_delete('cookie_name' )
__anonymize_ip('207.142.131.005' )
__anonymize_ip('001:0db8:0000:08d3:0000:8a2e:0070:7344' )
__anonymize_ip()
__password_strength('3iu' )
__password_strength('3iurehkHEDJ' )
__password_strength('3iurehkHEDJK§$R$A' )
__distance_haversine([48.576809 , 13.403207 ], [48.127719 , 11.575344 ])
__validate_iban('DE07123412341234123412' )
__validate_iban('DE07123412341234123442' )
__validate_url('https://vielhuber.de' )
__validate_email('david@vielhuber.de' )
__validate_date('2000-01-01' )
__validate_date('01.01.2000' )
__validate_date('29.02.2001' )
__validate_date(new DateTime('2000-01-01' ))
__validate_date(946713600 )
__validate_date_format('d.m.Y' )
__validate_date_format('Y-m-d' )
__validate_date_format('01.m.Y' )
__validate_date_format('foo' )
__validate_date_mod('+6 months' )
__validate_date_mod('foo' )
__date('2000-01-01' )
__date('2000-01-01' , 'd.m.Y' )
__date('2001-02-29' , 'd.m.Y' )
__date('2000-01-01' , '+6 months' )
__date('2000-01-01' , 'd.m.Y' , '+6 months' )
__date('01.01.2000' )
__date('01.01.20' )
__date('01.01.39' )
__date('now' )
__date('2019-12-02 12:00:00' , 'd.m.Y H:i:s' )
__date('2019-12-02T12:00:00' , 'd.m.Y H:i:s' )
__date()
__date('' )
__date(null )
__date('d.m.Y' ,null )
$unknown = null ; __date($unknown)
__date(strtotime('2000-01-01' ), 'd.m.Y' )
__date(strtotime('2000-01-01' ), 'd.m.Y' , '+6 months' )
__date(new DateTime('2000-01-01' ), 'd.m.Y' )
__date('d.m.Y' )
__date('d.m.Y' , 'now' )
__date('+6 months' )
__datetime('01.01.2000' )
__datetime('01.01.2000 18:00' )
__date_reset_time('2000-01-01 16:30:00' )
__date_reset_time('2000-01-01' )
__date_reset_time('01.01.2000' )
__age_from_date('2000-01-01' )
__age_from_date('2000-01-01' , '2010-01-01' )
__age_from_date_weeks('2000-01-01' )
__age_from_date_weeks('2000-01-01' , '2010-01-01' )
__age_from_date_days('2000-01-01' )
__age_from_date_days('2000-01-01' , '2010-01-01' )
setlocale(LC_TIME, 'de_DE.utf8' );
__strftime('%A, %d. %B %Y' , strtotime('2001-01-01' ));
__remove_zero_decimals(1337 )
__remove_zero_decimals('1337' )
__remove_zero_decimals('1337.40' )
__remove_zero_decimals('1337,40' )
__remove_zero_decimals(1337.0 )
__remove_zero_decimals(1337.4 )
__remove_zero_decimals(1337.42 )
__remove_zero_decimals(1337.424 )
__remove_leading_zeros('01337' )
__phone_normalize('(0)89-12 456 666' )
__phone_tokenize('(0)89-12 456 666' )
__phone_country_codes()
__phone_area_codes()
__phone_area_codes_landline()
__phone_area_codes_mobile()
__phone_is_landline('(0)89-12 456 666' )
__phone_is_mobile('(0)89-12 456 666' )
__email_tokenize_str2arr('Max Mustermann <mail1@tld.com>; mail2@tld.com' )
__email_tokenize_arr2str([['email' => 'mail1@tld.com' , 'name' => 'Max Mustermann' ],['email' => 'mail2@tld.com' , 'name' => null ]]);
__url_normalize('www.tld.com' )
__url_normalize('http://tld.com/' )
__minify_html('<!DOCTYPE html>
<title>shortest valid html5 document</title>
<p>yay</p>' )
__dom_to_str(__str_to_dom('<ul><li></li><li></li></ul>' ))
__dom_to_str(__str_to_dom('<custom-component @click.prevent="foo()"></custom-component>' ))
__translate_google('Sein oder Nichtsein; das ist hier die Frage.' , 'de' , 'en' , '**API Key**' )
__translate_microsoft('Sein oder Nichtsein; das ist hier die Frage.' , 'de' , 'en' , '**API Key**' )
__translate_deepl('Sein oder Nichtsein; das ist hier die Frage.' , 'de' , 'en' , '**API Key**' )
$ai = __ai(
service: 'chatgpt' ,
model: 'gpt-4o' ,
temperature: 0.7 ,
api_key: '**API Key**'
);
$ai->ask('Wer wurde 2018 Fußball-Weltmeister?' );
$ai->ask('Was ist auf dem Bild zu sehen?' , 'lorem.jpg' );
$ai->ask('Wie lautet das erste Wort in der PDF?' , 'lorem.pdf' );
$ai->ask('Fasse die folgenden Dokumente zusammen.' , ['1.pdf' ,'2.jpg' ]);
$ai = __ai(
session_id: $ai->session_id
);
$ai->ask('Was habe ich vorher gefragt?' );
$ai->cleanup();
$ai->cleanup_all();
$ai->enable_log('output.log' );
$ai->disable_log();
__remove_emoji('Lorem 🤷 ipsum ❤ dolor 🥺 med' )
__remove_accents('Ǻºĺ' )
__remove_accents('Äťśçĥ' )
__remove_accents('Äťśçĥ' , true )
__remove_non_printable_chars('foobar' )
__slug('This string will be sanitized!' )
__random_string()
__random_string(10 )
__random_string(16 , 'idkfa' )
__shuffle(['foo' ,'bar' ,'baz' ]);
__shuffle_assoc(['foo' => 'bar' , 'bar' => 'baz' , 'baz' => 'foo' ])
$arr = ['äther' , 'Äther2' , 'Ü12.pdf' , 'Ü2.pdf' ];
usort($arr, function ($a, $b) { return __mb_strcmp($a, $b); });
usort($arr, function ($a, $b) { return __mb_strcasecmp($a, $b); });
usort($arr, function ($a, $b) { return __mb_strnatcmp($a, $b); });
usort($arr, function ($a, $b) { return __mb_strnatcasecmp($a, $b); });
$arr = [['a' => 17 , 'b' => 42 ], ['a' => 13 , 'b' => 19 ]]
usort($arr, __array_multisort([ ['a' , 'asc' ], ['b' , 'asc' ] ]))
usort($arr, __array_multisort(function ($v) { return [ [$v['a' ], 'asc' ], [$v['b' ], 'asc' ] ]; }))
collect($arr)->sort( __array_multisort([ ['a' , 'asc' ], ['b' , 'asc' ] ]) )
$arr = [['foo' => 'zoo' ], ['foo' => 'Äther' ]]
usort($arr, __array_multisort([['foo' , 'asc' ]]))
$a = ['a' => 17 , 'b' => 42 , 'c' => 'foo' ]
$b = ['a' => 19 , 'b' => 20 , 'c' => 'bar' ]
$c = ['a' => 17 , 'b' => 42 , 'c' => 'baz' ]
$arr = [$a, $b, $c]
__array_group_by($arr, 'a' )
__array_group_by($arr, 'a' , 'b' )
__array_group_by($arr, function ($v) { return $v['a' ]; })
__array_group_by($arr, function ($v) { return $v['a' ]; }, function ($v) { return $v['b' ]; })
$arr = collect([collect($a), collect($b), collect($c)])
__array_group_by($arr, function ($v) { return $v->get('a' ); })
$a = ['a' => 17 , 'b' => 42 , 'c' => 'foo' ]
$b = ['a' => 19 , 'b' => 20 , 'c' => 'bar' ]
$c = ['a' => 17 , 'b' => 42 , 'c' => 'baz' ]
$arr = [$a, $b, $c]
__array_group_by_aggregate($arr, 'a' , [
'b' => function ($a, $b) { return $a+$b; },
'c' => function ($a, $b) { return $a.', ' .$b; },
])
__array_group_by_aggregate($arr, ['a' ,'b' ], [
'c' => function ($a, $b) { return $a.', ' .$b; },
])
__array_unique([1 ,2 ,2 ])
__array_unique([['foo' =>'bar' ],['bar' =>'baz' ],['foo' =>'bar' ]])
__array_map_deep(['foo' ,'bar' =>['baz' ,'gnarr' ]], function ($a) { return $a.'!' ; })
__array_map_deep([[[[[[[[[[[[[[[true ]]]]]]]]]]]]]]], function ($a) { return !$a; })
__array_map_deep(
[[[[[[[[[[[[[[[42 => 'no' , 7 => 'ok' ]]]]]]]]]]]]]]],
function ($value, $key) { return $key === 42 ? $value : $value . '!' ; }
)
__array_map_deep(
['foo' =>['bar' =>'baz' ],'bar' =>['baz' =>'gnarr' ],'gnarr' =>['foo' =>'gnaz' ]],
function ($value,$key,$key_chain) { return in_array('bar' ,$key_chain)?$value.'!' :$value; }
)
$output = [];
array_map_deep(
[1 =>[2 =>[3 =>[4 =>[5 =>'ok1' ],6 =>[7 =>'ok2' ]]]],8 =>'ok3' ],
function ($value,$key,$key_chain) use (&$output) { $output[] = $value.': ' .implode('.' ,$key_chain); }
)
echo implode(' - ' , $output)
__array_map_deep(['foo' ,'bar' =>(object)['baz' ,'gnarr' ]], function ($a) { return $a.'!' ; })
__array_map_deep(['foo' ,'bar' =>json_encode(['baz' ,'gnarr' ])], function ($a) { return $a.'!' ; })
__array_map_deep_all(['foo' =>'bar' ,'bar' =>['baz' =>'gnarr' ,'gnarr' =>'baz' ]], function ($value, $key, $key_chain) {
if (is_array($value) && array_key_exists('baz' , $value) && $value['baz' ] === 'gnarr' ) {
$value['gnarr' ] = 'baz2' ;
}
return $value;
})
$arr = ['foo' => 'bar' , 'bar' => ['baz' => 'gnarr' , 'gnarr' => 'baz' ]]
__array_walk_recursive_all($arr, function (&$value, $key, $key_chain) {
if (is_array($value) && array_key_exists('baz' , $value) && $value['baz' ] === 'gnarr' ) {
$value['gnarr' ] = 'baz2' ;
}
})
$arr
__array_filter_recursive_all(
['foo' => ['foo' => ['foo' => ['foo' => ['foo' => []]]]]],
function ($value, $key, $key_chain) { return $key === 'foo' && empty ($value); }
)
__array_map_keys(function ($k) { return $k.'!' ; }, ['foo' => 'bar' , 'bar' => 'baz' ])
__array_map_keys_values(function ($k,$v) { return [$k.'!' , $v.'?' ]; }, ['foo' => 'bar' , 'bar' => 'baz' ])
$answer = __ask('What\'s your name?' )
$answer = __ask('Choose your destiny:
[1] red pill
[2] blue pill' , [1 ,2 ])
echo 'Searching for TOE (theory of everything)...' .PHP_EOL;
$i = 0 ;
while ($i <= 100 ) {
__progress($i, 100 , 'Loading...' , 75 , '#' );
usleep($i < 90 ? 10000 : 250000 );
$i++;
}
echo PHP_EOL.'Answer: 42' ;
sprintf('%7.7s' , 'mäh' )
__mb_sprintf('%7.7s' , 'mäh' )
$data = ['foo' => 'bar' , 'bar' => 'baz' ];
$str = __encode_data($data)
__decode_data($str)
__decode_data(__encode_data(['foo' , 'bar' ]))
__decode_data(__encode_data('foo' , 'bar' ))
echo '<input name="foo[' .__encode_data($data).']" value="bar" />' ;
__decode_data(array_key_first($_POST['foo' ]))
foreach ($a as $a__value) { $index[__encode_data($a__value['foo' ],$a__value['bar' ])] = null ; }
foreach ($b as $b__value) { if (array_key_exists(__encode_data($b__value['foo' ],$b__value['bar' ]),$index)) { } }
__uuid()
__validate_uuid('19028aea-ccb6-4b32-9e5d-1243c3a77bb1' )
__validate_uuid('00000000-0000-0000-0000-000000000000' )
__validate_uuid('00000000-0000-0000-0000-000000000000' , false )
__pushId()
__strip('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam.' , 12 )
__strip_numeric('the answer is 42.00' )
__strip_nonnumeric('the answer is 42.00' )
__strip_numeric('the answer is 42.00' )
__strip_nondigit('the answer is 42' )
__strip_nonchars('the Änswer is 42.-+&!foo' )
__strip_whitespace('the answer is 42' )
__strip_whitespace('the answeris42' )
__strip_whitespace_collapsed('the answer is 42' )
__strip_whitespace_collapsed('the answer is 42 ' )
__strip_tags('<p>foo</p><iframe src="#"></iframe><script>alert();</script><p>bar</p>' , 'script' )
__strip_tags('<p>foo</p><iframe src="#"></iframe><script>alert();</script><p>bar</p>' , ['iframe' ,'script' ], true )
__split_newline('foo
bar
baz' )
__split_whitespace('DE07123412341234123412' , 4 )
__split_whitespace(' föö bäär ' , 3 )
__remove_emptylines('foo
bar
baz' )
__remove_newlines('foo
bar<br/>
baz' )
__remove_newlines('foo
bar<br/>
baz' , ' ' )
__br2nl('foo<br/>bar' )
__truncate_string('Lorem ipsum dolor sit amet, consectetuer.' , 20 );
__truncate_string('Lorem ipsum dolor sit amet, consectetuer.' , 20 , '…' );
__trim_whitespace(' string including nasty whitespace chars ' )
__atrim(['foo
' ,'bar' ,'
baz' ])
__trim_every_line('foo
bar
baz ' )
__trim('<br><br/><p></p>foo bar baz<br/><br/><br><br/>' , ['<br/>' ,'<br>' ,'<p></p>' ])
__ltrim('<br><br/><p></p>foo bar baz<br/><br/><br><br/>' , ['<br/>' ,'<br>' ,'<p></p>' ])
__rtrim('<br><br/><p></p>foo bar baz<br/><br/><br><br/>' , ['<br/>' ,'<br>' ,'<p></p>' ])
__arr_without(['foo' => 'bar' , 'bar' => 'baz' , 'baz' => 'foo' ], ['bar' , 'baz' ])
__strrev('hello❤️world' )
__string_is_json('[]' )
__string_is_json('{"foo":"bar"}' )
__string_is_json('["foo" => "bar"]' )
__string_is_json([])
__string_is_json((object)[])
__string_is_html('foo' )
__string_is_html('<p>foo</p>' )
__string_is_html('foo bar' )
__string_is_html('foo bar' )
__is_serialized('a:1:{s:3:"foo";s:3:"bar";}' )
__is_serialized('idkfa' )
__is_serialized('b:0;' )
__is_serialized('a:1:{s:3:\"foo\";s:3:\"bar\";}' )
__is_serialized('a:1:{42}' )
__is_base64_encoded('dGhpcyBpcyBjb29sIHN0dWZm' )
__is_base64_encoded('#ib3498r' )
__is_base64_encoded('al3Vna##2dqa#Gdm' )
__is_base64_encoded((object)[])
__is_eloquent_builder($var)
__extract('<a href="#foo">bar</a>' ,'href="' ,'">' )
__extract('<a href="#foo">bar</a>' ,'">' ,'</a' )
__strposx('bar foo baz foobar' , 'foo' )
__strposnth('bar foo baz foobar' , 'foo' , 2 )
$array = ['foo' ,'bar' ];
foreach ($array as $array__key=>$array__value)
{
if ( __fkey($array__key, $array) ) { }
if ( __lkey($array__key, $array) ) { }
}
$array = ['foo' ,'bar' ];
foreach ($array as $array__value)
{
$loop_status = __loop_status($array);
if ($loop_status->is_first) {}
if ($loop_status->is_last) {}
if ($loop_status->is_not_first) {}
if ($loop_status->is_not_last) {}
}
__last(['foo' , 'bar' , 'baz' ])
__first(['foo' , 'bar' , 'baz' ])
__first(['foo' => 'bar' , 'bar' => 'baz' ])
__first_key(['foo' => 'bar' , 'bar' => 'baz' ])
__rand(['foo' , 'bar' , 'baz' ])
__remove_first(['foo' , 'bar' , 'baz' ])
__remove_last(['foo' , 'bar' , 'baz' ])
__first_char_is_uppercase('Foo' )
__first_char_is_uppercase('bar' )
__set_first_char_uppercase('baz' )
__set_first_char_uppercase('übel' )
__array_to_object(['foo' ])
__array_to_object(['foo' ,'bar' ])
__array_to_object(['foo' => 'bar' ])
__array_to_object(['foo' ,'bar' => ['foo' ,'bar' ]])
__object_to_array((object)['foo' ])
__object_to_array((object)['foo' ,'bar' ])
__object_to_array((object)['foo' => 'bar' ])
__object_to_array((object)['foo' ,'bar' => (object)['foo' ,'bar' ]])
__array()
__array('foo' )
__array(['foo' ])
__array(['foo' ,'bar' ])
__array((object)['foo' ,'bar' ])
__array((object)['foo' ,'bar' => (object)['foo' ,'bar' ]])
__object()
__object('foo' )
__object(['foo' ])
__object(['foo' ,'bar' ])
__object(['foo' => 'bar' ])
__object((object)['foo' ,'bar' ])
__object(['foo' ,'bar' => ['foo' ,'bar' ]])
__can_be_looped([1 ,2 ])
__can_be_looped((object)[1 ,2 ])
__can_be_looped([])
$a = [1 , 2 ]; $b = [3 , 4 ]; $c = [5 , 6 ]; $output = [];
$fn = function ($x, $y, $z) use (&$output) { $output[] = $x . '' . $y . '' . $z; };
__foreach_nested($a, $b, $c, $fn);
print_r($output);
$arr = [0 => ['foo' ,0 ,'0' ,null ,'' ], null , 2 => [['' ,'' ],[null ]]];
__remove_empty($arr)
__remove_empty($arr, [0 ,'0' ])
__remove_empty($arr, null , function ($value) {
return (is_array($value) && empty ($value)) || (is_string($value) && $value === '' );
})
__remove_by_key([0 => 'foo' , 1 => 'bar' , 2 => 'baz' ], 1 )
__remove_by_key(['foo' => 1 , 'bar' => 2 , 'baz' => 3 ], 'foo' )
__remove_by_key((object)[0 => 'foo' , 1 => 'bar' , 2 => 'baz' ], 1 )
__remove_by_value([0 => 'foo' , 1 => 'bar' , 2 => 'baz' ], 'bar' )
__remove_by_value(['foo' => 1 , 'bar' => 2 , 'baz' => 3 ], 1 )
__remove_by_value((object)[0 => 'foo' , 1 => 'bar' , 2 => 'baz' ], 'bar' )
__arr_depth(['foo' => 'bar' , 'bar' => ['baz' => ['gnarr' => 'gnaz' ]]])
__arr_append(['foo' ], 'bar' )
__arr_prepend(['bar' ], 'foo' )
__arr_append(['foo' ], 'bar' , 42 %7 === 0 )
__arr_prepend(['bar' ], 'foo' , 0 %1 === 1 )
__arr_append(__arr_append(__arr_append([], 'foo' ), 'bar' , false ), 'baz' )
__inside_out_values([
'option1' => [0 => 'foo' , 1 => 'bar' , 2 => 'baz' , 3 => '' ],
'option2' => [0 => 'bar' , 1 => 'baz' , 2 => 'foo' , 3 => null ]
])
__arrays_to_objects(['foo' => ['bar' ,'baz' ], 'bar' => [(object)['id' => 7 , 'name' => 'foo' ], (object)['id' => 42 , 'name' => 'bar' ]]])
__array_get(['foo' =>['bar' =>['baz' =>42 ]]], 'foo.bar.baz' );
__array_set(['foo' =>['bar' =>['baz' =>42 ]]], 'foo.bar.baz' , 7 );
__highlight('that is a search string' , 'is' )
__highlight('abc def geh ijk lmn opq rst abc def geh ijk lmn opq rst' , 'ijk' , true , 5 )
__is_integer(0 )
__is_integer(42 )
__is_integer(4.2 )
__is_integer(0.42 )
__is_integer(42. )
__is_integer('42' )
__is_integer('a42' )
__is_integer('42a' )
__is_integer(0x24 )
__is_integer(8372468764378627868742367883268 )
__is_integer('8372468764378627868742367883268' )
__is_integer(' 1337' )
__is_integer('1337 ' )
__is_integer([])
__is_integer(null )
__is_integer(false )
__is_integer(true )
__float_to_ratio(1920 /600 )
__float_to_ratio(1 /3 )
__o($var)
__o($var1, $var2, $var3)
__o('<strong>foo</strong>' )
__d($var)
__flatten_keys(['foo' => ['bar' => 'baz' ]])
__flatten_values(['foo' => 'bar' , 'bar' => ['baz' , 'foo' ]])
__expl(' ' , 'foo bar baz' , 1 )
__expl(' ' , 'foo bar baz' )
__prg()
__prg('https://test.de' )
__redirect_to()
__redirect_to('https://test.de' )
__redirect_to('https://test.de' , 301 )
__redirect_to('https://test.de' , 302 )
__redirect_to('https://test.de' , 7 , 'html' )
system_message('foo' )
system_message('bar' , 'error' )
$system_messages = system_messages();
echo '<!DOCTYPE html><html lang="de"><body>' ;
foreach ($system_messages as $system_messages__value) {
echo '<div class="system-message system-message--' .$system_messages__value->type.'">' ;
echo $system_messages__value->content;
echo '</div>' ;
}
echo '</body></html>' ;
try {
__exception('foo' );
}
catch (\Throwable $t) {
__exception_message($t)
}
try {
__exception(['foo' => 'bar' ]);
}
catch (\Throwable $t) {
__exception_message($t)
}
try {
throw new \Exception ('bar' );
}
catch (\Throwable $t) {
__exception_message($t)
}
try {
__exception('foo' );
}
catch (\ExtendedException $t) {
__exception_message($t)
}
try {
throw new \Exception ('bar' );
}
catch (\ExtendedException $t) {
}
catch (\Exception $t) {
}
__success()
__error('missing data' )
$GLOBALS['t' ] = 0 ;
__hook_fire('hook_name' );
__hook_add('hook_name' , function () { $GLOBALS['t' ]++; });
__hook_fire('hook_name' );
__hook_fire('hook_name' );
__hook_add('hook_name' , function () { $GLOBALS['t' ] *= 2 ; });
__hook_fire('hook_name' );
__hook_fire('hook_name' );
$foo = 1 ;
__hook_add('filter_name' , function ($a) { return $a+1 ; }, 20 );
__hook_add('filter_name' , function ($a) { return $a*2 ; }, 10 );
__hook_add('filter_name' , function ($a) { return $a-3 ; }, PHP_INT_MAX);
$foo = __hook_fire('filter_name' , $foo);
$foo = __hook_fire('filter_name' , $foo);
__os()
__url()
__urlWithoutArgs()
__baseurl()
__baseurl(true )
__image_compress('input.jpg' )
__image_compress('input.jpg' , 70 )
__image_compress('input.jpg' , 70 , 'output.jpg' )
__image_orientate('input.jpg' )
__image_orientate('input.jpg' , 70 )
__image_orientate('input.jpg' , 70 , 'output.jpg' )
__file_extension('foo.jpg' )
__is_utf8('foo' )
__to_utf8('foo' )
__utf8_encode('foo' )
__utf8_decode('foo' )
__iptc_codes()
__iptc_code('Copyright' )
__iptc_keyword('2#116' )
__iptc_read('input.jpg' )
__iptc_read('input.jpg' , '2#116' )
__iptc_read('input.jpg' , 'Copyright' )
__iptc_write('input.jpg' , ['2#116' => '© Copyright 2021 by foobar' ])
__iptc_write('input.jpg' , '2#116' , '© Copyright 2021 by foobar' )
__iptc_write('input.jpg' , 'Copyright' , '© Copyright 2021 by foobar' )
__iptc_write('input.jpg' , 'Copyright' , null )
__iptc_write('input.jpg' , [])
define('ENCRYPTION_KEY' , '4736d52f85bdb63e46bf7d6d41bbd551af36e1bfb7c68164bf81e2400d291319' )
__decrypt(__encrypt('foo' ))
__decrypt(__encrypt('bar' ,'known_salt' ))
define('ENCRYPTION_FOLDER' , $_SERVER['DOCUMENT_ROOT' ].'/encryption' )
__decrypt_poor(__encrypt_poor('foo' ))
$token = __encrypt_poor('bar' )
__decrypt_poor($token, true )
__decrypt_poor($token)
__files_in_folder()
__files_in_folder('.' )
__files_in_folder('foo' )
__files_in_folder('foo' , true )
__files_in_folder('foo' , true , ['.git' , '.gitkeep' ])
__files_in_folder('foo' , true , ['.git' , '.gitkeep' ], true )
__rrmdir('foo' )
__zip('output.zip' , 'folder' )
__zip('output.zip' , 'file1.jpg' )
__zip('output.zip' , ['file1.jpg' , 'subfolder/file2.jpg' ])
__zip('output.zip' , ['file1.jpg' , 'subfolder/file2.jpg' ], true )
__unzip('output.zip' , '.' )
__is_external('https://github.com/vielhuber/stringhelper' )
__is_external('https://github.com/vielhuber/stringhelper/' )
__is_external('https://github.com/vielhuber/stringhelper/issues' )
__is_external('https://github.com/vielhuber/stringhelper/test.pdf' )
__is_external('tel:+4989215400142' )
__is_external('mailto:david@vielhuber.de' )
__is_external('https://vielhuber.de' )
__is_external('https://vielhuber.de/test.pdf' )
$_GET = ['page_id' => '13' , 'code' => '<h1>Hello World!</h1>' ];
$_POST = ['foo' => 'bar' , 42 => "\0" ];
__get('foo' )
__get('page_id' )
__post('foo' )
__filter_url_args('https://ai?foo=bar&bar=baz&baz=foo' , ['foo' ,'bar' ])
__clean_up_get()
__clean_up_post()
__clean_up()
__read_env('.env' )
__is_repetitive_action();
__is_repetitive_action('name' );
__is_repetitive_action('name' , 60 );
__is_repetitive_action('name' , 1 /60 );
__is_repetitive_action('name' , 60 , ['127.0.0.1' ,'0.0.0.0' ]);
__has_spamwords('This is cool stuff.' )
__has_spamwords('I do spy software your website.' )
__has_spamwords('Hongsheng Ltd' )
__has_spamwords('Hongsheng Ltd' , ['hongsheng' ])
__has_spamwords('I do spy software your website.' , null , ['spy software' ])
__ip_is_on_spamlist('191.101.31.148' )
__ip_is_on_spamlist('127.0.0.1' )
__referer()
__fetch('https://httpbin.org/anything' )
__fetch('https://httpbin.org/anything' , 'curl' )
__fetch('https://httpbin.org/anything' , 'php' )
__curl(
'https://httpbin.org/anything' ,
['foo' => 'bar' ],
'POST' ,
['Bar' => 'baz' ],
false ,
true ,
60 ,
['username' => 'password' ],
['foo' => 'bar' ],
true ,
'username:password@192.168.178.1:8080'
)
__curl('https://httpbin.org/anything' )
__curl('https://httpbin.org/anything' , ['foo' => 'bar' ], 'POST' )
__curl('https://httpbin.org/anything' , ['foo' => 'bar' ], 'POST' , ['Bar' => 'baz' ])
__curl('https://vielhuber.de' )
__curl('https://httpbin.org/anything' , ['foo' => 'bar' ], 'PUT' )
__curl('https://httpbin.org/anything' , null , 'DELETE' )
__curl('https://vielhuber.de/wp-login.php' , ['log' => 'username' , 'pwd' , 'password' ], 'POST' , null , true , false )
__curl('https://vielhuber.de/wp-admin/options.php' , null , 'GET' , null , true )
__curl('https://vielhuber.de/wp-admin/options.php' , null , 'GET' , null , false , false , 60 , null , $_COOKIE)
__get_mime_type('foo.png' )
__mime_type_to_extension('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' )
__extension_to_mime_types('xlsx' )
__reverse_proxy('https://tld.com' , [
'*' => [
'replacements' => [
['location.origin!==n.origin' , '1===0&&location.origin!==n.origin' ],
['/(https:\/\/.+\.example\.net\/assets\/js\/another\/asset.js)/' , __urlWithoutArgs().'?url=$1' ],
['</head>' , '<style>.ads { display:none; }</style></head>' ]
],
'dom' => function ($DOMDocument, $DOMXPath) {
$DOMXPath->query('/html/body//*[@id="foo"]' )[0 ]->setAttribute('data-bar' ,'baz' );
},
'css' => '.ads { display:none; }' ,
'js' => 'alert("ok");'
],
'example.js' => [],
'/regex-match-v.*\.js/' => []
])
use vielhuber \stringhelper \__ ;
__::x(42 );