Skip to content

Instantly share code, notes, and snippets.

Segu msegu

Block or report user

Report or block msegu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@msegu
msegu / inArray.php
Created Jul 18, 2018
php in_array() extension
View inArray.php
You can use function inArray below, to search:
- multidimensional arrays
- for substrings (case [in]sensitive)
- for sub-arrays
- get array of keys of found values
<?php
/** Function 'inArray' checks if a value exists in an array (also multidimensional): if string as substring (case-[in]sensitive), or other value as a element of the same type
*
* @param mixed $needle Value to find (string: as (sub)string, array: as (sub)array, other: as exact element)
* @param array $haystack The array for search (can be multidimensional)
@msegu
msegu / toURI.php
Last active Aug 8, 2018
URL/URI full encoding
View toURI.php
<?php
/*
Need to encode given (finished) path and query?, for example
'http://example.org:port/path1/path2/data?key1=value1&argument#fragment' (1)
or 'scheme://user:password@example.com:port/path1/path2/data?key1=value1&key2=value2#fragment' (2)
e.g. this (2) should be encoded:
'scheme://'.rawurlencode('user').':'.rawurlencode('password').'@example.com:port/'
.rawurlencode('path1').'/'.rawurlencode('path2').'/'.rawurlencode('data')
.'?'.htmlentities(urlencode('key1').'='.urlencode('value1').'&'.urlencode('key2').'='.urlencode('value2'))
@msegu
msegu / gzdecodeM.php
Created Jul 11, 2018
php gzdecode() replacement/extension
View gzdecodeM.php
<?php
/** function 'gzdecodeM'
* @param data string .GZ data
* @param gz array (optional) Returned array of file sections properties
* @param error string (optional) Returned error (if any)
* @param maxlength int (optional) Max length of uncompressed data
* @param sects string (optional) Sections to uncompress, e.g. '0-3, 5, 8-p100000, 100-' (where: '0' - section number, 'p0' - file .gz position in Bytes, 'x-' - from section x to the end of file)
* Note: sections are extracted once and in the order they are in the .gz file, not how they are listed
* @return Uncompressed data (if OK)
*/
@msegu
msegu / parse_ini_stringM.php
Last active Jul 10, 2018
php parse_ini_string() fix
View parse_ini_stringM.php
<?php
/*
php parse_ini_string() extension
With function below you can:
- fix unvalued fields ('key' (invalid) ==> 'key=' (OK) )
- fix unquotted values with equal sign '=' ('key=value_part1=value_part2' ==> 'key="value_part1=value_part2"')
- fix (solve) multidimensional arrays (makes 'key[key1][key2]=value' valid)
- fix any reading errors (wrong lines, they may be later rawurldecoded with md5 checking)
*/
You can’t perform that action at this time.