Skip to content

Instantly share code, notes, and snippets.

msegu / inArray.php
Created July 18, 2018 00:18
php in_array() extension
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
/** 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 / toURI.php
Last active May 26, 2020 16:34
URL/URI full encoding
Need to encode given (finished) path and query?, for example
'' (1)
or 'scheme://' (2)
e.g. this (2) should be encoded:
msegu / gzdecodeM.php
Created July 11, 2018 20:43
php gzdecode() replacement/extension
/** 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 / parse_ini_stringM.php
Last active July 10, 2018 20:02
php parse_ini_string() fix
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)