This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ip_in_cidr($ip, $cidr) { | |
// Determine IP version with FILTER_VALIDATE_IP | |
$ip_version = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? 4 : | |
(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? 6 : false); | |
if (!$ip_version) { | |
throw new InvalidArgumentException("{$ip} is not a valid IP address"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Quicksorting (with partition) implementation to sort SplFixedArray on a specific key, | |
* I could not find this and I needed this because I'm stuck on PHP5.6 at work -- 2023-05-04 wuhei | |
* | |
* @param $arr SplFixedArray, array to sort | |
* @param $key mixed, array key to sort on | |
* @param $desc bool if true, sort descending | |
* @param $leftIndex int, left index of the array to sort, defaults to 0 | |
* @param $rightIndex int, right index of the array to sort, defaults to count($arr) - 1 | |
* @return mixed |