* @version $Revision: 1.8 $ * @since PHP 5 */ if (!defined('FILE_USE_INCLUDE_PATH')) { define('FILE_USE_INCLUDE_PATH', 1); } if (!defined('FILE_IGNORE_NEW_LINES')) { define('FILE_IGNORE_NEW_LINES', 2); } if (!defined('FILE_SKIP_EMPTY_LINES')) { define('FILE_SKIP_EMPTY_LINES', 4); } if (!defined('FILE_APPEND')) { define('FILE_APPEND', 8); } if (!defined('FILE_NO_DEFAULT_CONTEXT')) { define('FILE_NO_DEFAULT_CONTEXT', 16); } /** * Replace PHP_EOL constant * * @category PHP * @package PHP_Compat * @link http://php.net/reserved.constants.core * @author Aidan Lister * @version $Revision: 1.2 $ * @since PHP 5.0.2 */ if (!defined('PHP_EOL')) { switch (strtoupper(substr(PHP_OS, 0, 3))) { // Windows case 'WIN': define('PHP_EOL', "\r\n"); break; // Mac case 'DAR': define('PHP_EOL', "\r"); break; // Unix default: define('PHP_EOL', "\n"); } } /** * Replace tokenizer constants * * @category PHP * @package PHP_Compat * @link http://php.net/ref.tokenizer * @author Aidan Lister * @version $Revision: 1.4 $ * @since PHP 5 */ if (!defined('T_ML_COMMENT')) { define('T_ML_COMMENT', T_COMMENT); } if (!defined('T_DOC_COMMENT')) { define('T_DOC_COMMENT', T_ML_COMMENT); } if (!defined('T_OLD_FUNCTION')) { define('T_OLD_FUNCTION', -1); } if (!defined('T_ABSTRACT')) { define('T_ABSTRACT', -1); } if (!defined('T_CATCH')) { define('T_CATCH', -1); } if (!defined('T_FINAL')) { define('T_FINAL', -1); } if (!defined('T_INSTANCEOF')) { define('T_INSTANCEOF', -1); } if (!defined('T_PRIVATE')) { define('T_PRIVATE', -1); } if (!defined('T_PROTECTED')) { define('T_PROTECTED', -1); } if (!defined('T_PUBLIC')) { define('T_PUBLIC', -1); } if (!defined('T_THROW')) { define('T_THROW', -1); } if (!defined('T_TRY')) { define('T_TRY', -1); } if (!defined('T_CLONE')) { define('T_CLONE', -1); } /** * Replace array_combine() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_combine * @author Aidan Lister * @version $Revision: 1.21 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('array_combine')) { function array_combine($keys, $values) { if (!is_array($keys)) { user_error('array_combine() expects parameter 1 to be array, ' . gettype($keys) . ' given', E_USER_WARNING); return; } if (!is_array($values)) { user_error('array_combine() expects parameter 2 to be array, ' . gettype($values) . ' given', E_USER_WARNING); return; } $key_count = count($keys); $value_count = count($values); if ($key_count !== $value_count) { user_error('array_combine() Both parameters should have equal number of elements', E_USER_WARNING); return false; } if ($key_count === 0 || $value_count === 0) { user_error('array_combine() Both parameters should have number of elements at least 0', E_USER_WARNING); return false; } $keys = array_values($keys); $values = array_values($values); $combined = array(); for ($i = 0; $i < $key_count; $i++) { $combined[$keys[$i]] = $values[$i]; } return $combined; } } /** * Replace array_diff_key() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_diff_key * @author Tom Buskens * @version $Revision: 1.4 $ * @since PHP 5.0.2 * @require PHP 4.0.0 (user_error) */ if (!function_exists('array_diff_key')) { function array_diff_key() { $args = func_get_args(); if (count($args) < 2) { user_error('Wrong parameter count for array_diff_key()', E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_diff_key() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } $result = $args[0]; foreach ($args[0] as $key1 => $value1) { for ($i = 1; $i !== $array_count; $i++) { foreach ($args[$i] as $key2 => $value2) { if ((string) $key1 === (string) $key2) { unset($result[$key2]); break 2; } } } } return $result; } } /** * Replace array_diff_uassoc() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_diff_uassoc * @version $Revision: 1.2 $ * @since PHP 5.0.0 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_diff_uassoc')) { function array_diff_uassoc() { // Sanity check $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_diff_uassoc()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0] . '::' . $compare_func[1]; } user_error('array_diff_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_diff_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $result = array(); foreach ($args[0] as $k => $v) { for ($i = 1; $i < $array_count; $i++) { foreach ($args[$i] as $kk => $vv) { if ($v == $vv) { $compare = call_user_func_array($compare_func, array($k, $kk)); if ($compare == 0) { continue 3; } } } } $result[$k] = $v; } return $result; } } /** * Replace array_diff_ukey() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_diff_ukey * @author Tom Buskens * @version $Revision: 1.4 $ * @since PHP 5.0.2 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_diff_ukey')) { function array_diff_ukey() { $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_diff_ukey()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0].'::'.$compare_func[1]; } user_error('array_diff_ukey() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_diff_ukey() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $result = $args[0]; foreach ($args[0] as $key1 => $value1) { for ($i = 1; $i !== $array_count; $i++) { foreach ($args[$i] as $key2 => $value2) { if (!(call_user_func($compare_func, (string) $key1, (string) $key2))) { unset($result[$key1]); break 2; } } } } return $result; } } /** * Replace array_intersect_key() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_intersect_key * @author Tom Buskens * @version $Revision: 1.4 $ * @since PHP 5.0.2 * @require PHP 4.0.0 (user_error) */ if (!function_exists('array_intersect_key')) { function array_intersect_key() { $args = func_get_args(); if (count($args) < 2) { user_error('Wrong parameter count for array_intersect_key()', E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_intersect_key() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $result = array(); foreach ($args[0] as $key1 => $value1) { for ($i = 1; $i !== $array_count; $i++) { foreach ($args[$i] as $key2 => $value2) { if ((string) $key1 === (string) $key2) { $result[$key1] = $value1; } } } } return $result; } } /** * Replace array_intersect_assoc() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_intersect_uassoc * @author Aidan Lister * @version $Revision: 1.5 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_intersect_uassoc')) { function array_intersect_uassoc() { // Sanity check $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_intersect_ukey()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0] . '::' . $compare_func[1]; } user_error('array_intersect_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_intersect_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $result = array(); foreach ($args[0] as $k => $v) { for ($i = 0; $i < $array_count; $i++) { $match = false; foreach ($args[$i] as $kk => $vv) { $compare = call_user_func_array($compare_func, array($k, $kk)); if ($compare === 0 && $v == $vv) { $match = true; continue 2; } } if ($match === false) { continue 2; } } if ($match === true) { $result[$k] = $v; } } return $result; } } /** * Replace array_intersect_ukey() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_intersect_ukey * @author Tom Buskens * @version $Revision: 1.4 $ * @since PHP 5.0.2 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_intersect_ukey')) { function array_intersect_ukey() { $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_intersect_ukey()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0].'::'.$compare_func[1]; } user_error('array_diff_ukey() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_intersect_ukey() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $result = array(); foreach ($args[0] as $key1 => $value1) { for ($i = 1; $i !== $array_count; $i++) { foreach ($args[$i] as $key2 => $value2) { if (!(call_user_func($compare_func, (string) $key1, (string) $key2))) { $result[$key1] = $value1; break 2; } } } } return $result; } } /** * Replace array_product() * * @category PHP * @package PHP_Compat * @link http://php.net/time_sleep_until * @author Arpad Ray * @version $Revision: 1.1 $ * @since PHP 5.1.0 * @require PHP 4.0.1 (trigger_error) */ if (!function_exists('array_product')) { function array_product($array) { if (!is_array($array)) { trigger_error('The argument should be an array', E_USER_WARNING); return; } if (empty($array)) { return 0; } $r = 1; foreach ($array as $v) { $r *= $v; } return $r; } } /** * Replace array_udiff_assoc() * * @category PHP * @package PHP_Compat * @author Stephan Schmidt * @author Aidan Lister * @version $Revision: 1.14 $ * @link http://php.net/function.array-udiff-assoc * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_udiff_assoc')) { function array_udiff_assoc() { $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_udiff_assoc()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0] . '::' . $compare_func[1]; } user_error('array_udiff_assoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $count = count($args); for ($i = 0; $i < $count; $i++) { if (!is_array($args[$i])) { user_error('array_udiff_assoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } $diff = array (); // Traverse values of the first array foreach ($args[0] as $key => $value) { // Check all arrays for ($i = 1; $i < $count; $i++) { if (!array_key_exists($key, $args[$i])) { continue; } $result = call_user_func($compare_func, $value, $args[$i][$key]); if ($result === 0) { continue 2; } } $diff[$key] = $value; } return $diff; } } /** * Replace array_udiff() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_udiff * @author Stephan Schmidt * @author Aidan Lister * @version $Revision: 1.10 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_udiff')) { function array_udiff() { $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_udiff()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0] . '::' . $compare_func[1]; } user_error('array_udiff() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $cnt = count($args); for ($i = 0; $i < $cnt; $i++) { if (!is_array($args[$i])) { user_error('array_udiff() Argument #' . ($i + 1). ' is not an array', E_USER_WARNING); return; } } $diff = array (); // Traverse values of the first array foreach ($args[0] as $key => $value) { // Check all arrays for ($i = 1; $i < $cnt; $i++) { foreach ($args[$i] as $cmp_value) { $result = call_user_func($compare_func, $value, $cmp_value); if ($result === 0) { continue 3; } } } $diff[$key] = $value; } return $diff; } } /** * Replace array_udiff_uassoc() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_udiff_uassoc * @author Aidan Lister * @version $Revision: 1.8 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_udiff_uassoc')) { function array_udiff_uassoc() { $args = func_get_args(); if (count($args) < 3) { user_error('Wrong parameter count for array_udiff_uassoc()', E_USER_WARNING); return; } // Get compare function $compare_func = array_pop($args); if (!is_callable($compare_func)) { if (is_array($compare_func)) { $compare_func = $compare_func[0] . '::' . $compare_func[1]; } user_error('array_udiff_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $count = count($args); for ($i = 0; $i < $count; $i++) { if (!is_array($args[$i])) { user_error('array_udiff_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Traverse values of the first array $diff = array (); foreach ($args[0] as $key => $value) { // Check all arrays for ($i = 1; $i < $count; $i++) { if (!array_key_exists($key, $args[$i])) { continue; } $result = call_user_func($compare_func, $value, $args[$i][$key]); if ($result === 0) { continue 2; } } $diff[$key] = $value; } return $diff; } } /** * Replace array_uintersect_assoc() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_uintersect_assoc * @author Tom Buskens * @author Aidan Lister * @version $Revision: 1.9 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_uintersect_assoc')) { function array_uintersect_assoc() { $args = func_get_args(); if (count($args) < 3) { user_error('wrong parameter count for array_uintersect_assoc()', E_USER_WARNING); return; } // Get compare function $user_func = array_pop($args); if (!is_callable($user_func)) { if (is_array($user_func)) { $user_func = $user_func[0] . '::' . $user_func[1]; } user_error('array_uintersect_assoc() Not a valid callback ' . $user_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i < $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_uintersect_assoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $output = array(); foreach ($args[0] as $key => $item) { for ($i = 1; $i !== $array_count; $i++) { if (array_key_exists($key, $args[$i])) { $compare = call_user_func($user_func, $item, $args[$i][$key]); if ($compare === 0) { $output[$key] = $item; } } } } return $output; } } /** * Replace array_uintersect() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_uintersect * @author Tom Buskens * @author Aidan Lister * @version $Revision: 1.9 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_uintersect')) { function array_uintersect() { $args = func_get_args(); if (count($args) < 3) { user_error('wrong parameter count for array_uintersect()', E_USER_WARNING); return; } // Get compare function $user_func = array_pop($args); if (!is_callable($user_func)) { if (is_array($user_func)) { $user_func = $user_func[0] . '::' . $user_func[1]; } user_error('array_uintersect() Not a valid callback ' . $user_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); for ($i = 0; $i < $array_count; $i++) { if (!is_array($args[$i])) { user_error('array_uintersect() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Compare entries $output = array(); foreach ($args[0] as $key => $item) { for ($i = 1; $i !== $array_count; $i++) { $array = $args[$i]; foreach($array as $key0 => $item0) { if (!call_user_func($user_func, $item, $item0)) { $output[$key] = $item; } } } } return $output; } } /** * Replace array_uintersect_uassoc() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_uintersect_uassoc * @author Aidan Lister * @version $Revision: 1.12 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_uintersect_uassoc')) { function array_uintersect_uassoc() { $args = func_get_args(); if (count($args) < 4) { user_error('Wrong parameter count for array_uintersect_uassoc()', E_USER_WARNING); return; } // Get key_compare_func $key_compare_func = array_pop($args); if (!is_callable($key_compare_func)) { if (is_array($key_compare_func)) { $key_compare_func = $key_compare_func[0] . '::' . $key_compare_func[1]; } user_error('array_uintersect_uassoc() Not a valid callback ' . $key_compare_func, E_USER_WARNING); return; } // Get data_compare_func $data_compare_func = array_pop($args); if (!is_callable($data_compare_func)) { if (is_array($data_compare_func)) { $data_compare_func = $data_compare_func[0] . '::' . $data_compare_func[1]; } user_error('array_uintersect_uassoc() Not a valid callback ' . $data_compare_func, E_USER_WARNING); return; } // Check arrays $count = count($args); for ($i = 0; $i !== $count; $i++) { if (!is_array($args[$i])) { user_error('array_uintersect_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } } // Traverse values of the first array $intersect = array (); foreach ($args[0] as $key => $value) { // Check against each array for ($i = 1; $i < $count; $i++) { // Traverse each element in current array foreach ($args[$i] as $ckey => $cvalue) { // Compare key and value if (call_user_func($key_compare_func, $key, $ckey) === 0 && call_user_func($data_compare_func, $value, $cvalue) === 0) { $intersect[$key] = $value; continue; } } } } return $intersect; } } /** * Replace array_walk_recursive() * * @category PHP * @package PHP_Compat * @link http://php.net/function.array_walk_recursive * @author Tom Buskens * @author Aidan Lister * @version $Revision: 1.7 $ * @since PHP 5 * @require PHP 4.0.6 (is_callable) */ if (!function_exists('array_walk_recursive')) { function array_walk_recursive(&$input, $funcname) { if (!is_callable($funcname)) { if (is_array($funcname)) { $funcname = $funcname[0] . '::' . $funcname[1]; } user_error('array_walk_recursive() Not a valid callback ' . $user_func, E_USER_WARNING); return; } if (!is_array($input)) { user_error('array_walk_recursive() The argument should be an array', E_USER_WARNING); return; } $args = func_get_args(); foreach ($input as $key => $item) { if (is_array($item)) { array_walk_recursive($item, $funcname, $args); $input[$key] = $item; } else { $args[0] = &$item; $args[1] = &$key; call_user_func_array($funcname, $args); $input[$key] = $item; } } } } /** * Replace bcinvert() * * @category PHP * @package PHP_Compat * @link http://php.net/function.bcinvert * @author Sara Golemon * @version $Revision: 1.2 $ * @since PHP 5.2.0 * @require PHP 4.0.4 (call_user_func_array) */ if (!function_exists('bcinvert')) { function bcinvert($a, $n) { // Sanity check if (!is_scalar($a)) { user_error('bcinvert() expects parameter 1 to be string, ' . gettype($a) . ' given', E_USER_WARNING); return false; } if (!is_scalar($n)) { user_error('bcinvert() expects parameter 2 to be string, ' . gettype($n) . ' given', E_USER_WARNING); return false; } $u1 = $v2 = '1'; $u2 = $v1 = '0'; $u3 = $n; $v3 = $a; while (bccomp($v3, '0')) { $q0 = bcdiv($u3, $v3); $t1 = bcsub($u1, bcmul($q0, $v1)); $t2 = bcsub($u2, bcmul($q0, $v2)); $t3 = bcsub($u3, bcmul($q0, $v3)); $u1 = $v1; $u2 = $v2; $u3 = $v3; $v1 = $t1; $v2 = $t2; $v3 = $t3; } if (bccomp($u2, '0') < 0) { return bcadd($u2, $n); } else { return bcmod($u2, $n); } } } /** * Replace bcpowmod() * * @category PHP * @package PHP_Compat * @link http://php.net/function.bcpowmod * @author Sara Golemon * @version $Revision: 1.2 $ * @since PHP 5.0.0 * @require PHP 4.0.0 (user_error) */ if (!function_exists('bcpowmod')) { function bcpowmod($x, $y, $modulus, $scale) { // Sanity check if (!is_scalar($x)) { user_error('bcpowmod() expects parameter 1 to be string, ' . gettype($x) . ' given', E_USER_WARNING); return false; } if (!is_scalar($y)) { user_error('bcpowmod() expects parameter 2 to be string, ' . gettype($y) . ' given', E_USER_WARNING); return false; } if (!is_scalar($modulus)) { user_error('bcpowmod() expects parameter 3 to be string, ' . gettype($modulus) . ' given', E_USER_WARNING); return false; } if (!is_scalar($scale)) { user_error('bcpowmod() expects parameter 4 to be integer, ' . gettype($scale) . ' given', E_USER_WARNING); return false; } $t = '1'; while (bccomp($y, '0')) { if (bccomp(bcmod($y, '2'), '0')) { $t = bcmod(bcmul($t, $x), $modulus); $y = bcsub($y, '1'); } $x = bcmod(bcmul($x, $x), $modulus); $y = bcdiv($y, '2'); } return $t; } } /** * Replace clone() * * @category PHP * @package PHP_Compat * @link http://php.net/language.oop5.cloning * @author Aidan Lister * @version $Revision: 1.3 $ * @since PHP 5.0.0 * @require PHP 4.0.0 (user_error) */ if (version_compare(phpversion(), '5.0') === -1) { // Needs to be wrapped in eval as clone is a keyword in PHP5 eval(' function clone($object) { // Sanity check if (!is_object($object)) { user_error(\'clone() __clone method called on non-object\', E_USER_WARNING); return; } // Use serialize/unserialize trick to deep copy the object $object = unserialize(serialize($object)); // If there is a __clone method call it on the "new" class if (method_exists($object, \'__clone\')) { $object->__clone(); } return $object; } '); } /** * Replace convert_uudecode() * * @category PHP * @package PHP_Compat * @link http://php.net/function.convert_uudecode * @author Michael Wallner * @author Aidan Lister * @version $Revision: 1.8 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('convert_uudecode')) { function convert_uudecode($string) { // Sanity check if (!is_scalar($string)) { user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING); return false; } if (strlen($string) < 8) { user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING); return false; } $decoded = ''; foreach (explode("\n", $string) as $line) { $c = count($bytes = unpack('c*', substr(trim($line), 1))); while ($c % 4) { $bytes[++$c] = 0; } foreach (array_chunk($bytes, 4) as $b) { $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20; $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20; $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20; $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20; $b0 <<= 2; $b0 |= ($b1 >> 4) & 0x03; $b1 <<= 4; $b1 |= ($b2 >> 2) & 0x0F; $b2 <<= 6; $b2 |= $b3 & 0x3F; $decoded .= pack('c*', $b0, $b1, $b2); } } return rtrim($decoded, "\0"); } } /** * Replace convert_uuencode() * * @category PHP * @package PHP_Compat * @link http://php.net/function.convert_uuencode * @author Michael Wallner * @author Aidan Lister * @version $Revision: 1.7 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('convert_uuencode')) { function convert_uuencode($string) { // Sanity check if (!is_scalar($string)) { user_error('convert_uuencode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING); return false; } $u = 0; $encoded = ''; while ($c = count($bytes = unpack('c*', substr($string, $u, 45)))) { $u += 45; $encoded .= pack('c', $c + 0x20); while ($c % 3) { $bytes[++$c] = 0; } foreach (array_chunk($bytes, 3) as $b) { $b0 = ($b[0] & 0xFC) >> 2; $b1 = (($b[0] & 0x03) << 4) + (($b[1] & 0xF0) >> 4); $b2 = (($b[1] & 0x0F) << 2) + (($b[2] & 0xC0) >> 6); $b3 = $b[2] & 0x3F; $b0 = $b0 ? $b0 + 0x20 : 0x60; $b1 = $b1 ? $b1 + 0x20 : 0x60; $b2 = $b2 ? $b2 + 0x20 : 0x60; $b3 = $b3 ? $b3 + 0x20 : 0x60; $encoded .= pack('c*', $b0, $b1, $b2, $b3); } $encoded .= "\n"; } // Add termination characters $encoded .= "\x60\n"; return $encoded; } } /** * Replace debug_print_backtrace() * * @category PHP * @package PHP_Compat * @link http://php.net/function.debug_print_backtrace * @author Laurent Laville * @author Aidan Lister * @version $Revision: 1.3 $ * @since PHP 5 * @require PHP 4.3.0 (debug_backtrace) */ if (!function_exists('debug_print_backtrace')) { function debug_print_backtrace() { // Get backtrace $backtrace = debug_backtrace(); // Unset call to debug_print_backtrace array_shift($backtrace); // Iterate backtrace $calls = array(); foreach ($backtrace as $i => $call) { $location = $call['file'] . ':' . $call['line']; $function = (isset($call['class'])) ? $call['class'] . '.' . $call['function'] : $call['function']; $params = ''; if (isset($call['args'])) { $params = implode(', ', $call['args']); } $calls[] = sprintf('#%d %s(%s) called at [%s]', $i, $function, $params, $location); } echo implode("\n", $calls); } } /** * Replace file_get_contents() * * @category PHP * @package PHP_Compat * @link http://php.net/function.file_get_contents * @author Aidan Lister * @version $Revision: 1.21 $ * @internal resource_context is not supported * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('file_get_contents')) { function file_get_contents($filename, $incpath = false, $resource_context = null) { if (false === $fh = fopen($filename, 'rb', $incpath)) { user_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING); return false; } clearstatcache(); if ($fsize = @filesize($filename)) { $data = fread($fh, $fsize); } else { $data = ''; while (!feof($fh)) { $data .= fread($fh, 8192); } } fclose($fh); return $data; } } if (!defined('FILE_USE_INCLUDE_PATH')) { define('FILE_USE_INCLUDE_PATH', 1); } if (!defined('LOCK_EX')) { define('LOCK_EX', 2); } if (!defined('FILE_APPEND')) { define('FILE_APPEND', 8); } /** * Replace file_put_contents() * * @category PHP * @package PHP_Compat * @link http://php.net/function.file_put_contents * @author Aidan Lister * @version $Revision: 1.25 $ * @internal resource_context is not supported * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('file_put_contents')) { function file_put_contents($filename, $content, $flags = null, $resource_context = null) { // If $content is an array, convert it to a string if (is_array($content)) { $content = implode('', $content); } // If we don't have a string, throw an error if (!is_scalar($content)) { user_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING); return false; } // Get the length of data to write $length = strlen($content); // Check what mode we are using $mode = ($flags & FILE_APPEND) ? 'a' : 'wb'; // Check if we're using the include path $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ? true : false; // Open the file for writing if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) { user_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING); return false; } // Attempt to get an exclusive lock $use_lock = ($flags & LOCK_EX) ? true : false ; if ($use_lock === true) { if (!flock($fh, LOCK_EX)) { return false; } } // Write to the file $bytes = 0; if (($bytes = @fwrite($fh, $content)) === false) { $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', $length, $filename); user_error($errormsg, E_USER_WARNING); return false; } // Close the handle @fclose($fh); // Check all the data was written if ($bytes != $length) { $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', $bytes, $length); user_error($errormsg, E_USER_WARNING); return false; } // Return length return $bytes; } } /** * Replace fprintf() * * @category PHP * @package PHP_Compat * @link http://php.net/function.fprintf * @author Aidan Lister * @version $Revision: 1.13 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('fprintf')) { function fprintf() { $args = func_get_args(); if (count($args) < 2) { user_error('Wrong parameter count for fprintf()', E_USER_WARNING); return; } $resource_handle = array_shift($args); $format = array_shift($args); if (!is_resource($resource_handle)) { user_error('fprintf() supplied argument is not a valid stream resource', E_USER_WARNING); return false; } return fwrite($resource_handle, vsprintf($format, $args)); } } /** * Replace fprintf() * * @category PHP * @package PHP_Compat * @link http://php.net/function.fprintf * @author Twebb * @author Aidan Lister * @version $Revision: 1.2 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('fputcsv')) { function fputcsv($handle, $fields, $delimiter = ',', $enclosure = '"') { // Sanity Check if (!is_resource($handle)) { user_error('fputcsv() expects parameter 1 to be resource, ' . gettype($handle) . ' given', E_USER_WARNING); return false; } $str = ''; foreach ($fields as $cell) { $cell = str_replace($enclosure, $enclosure . $enclosure, $cell); if (strchr($cell, $delimiter) !== false || strchr($cell, $enclosure) !== false || strchr($cell, "\n") !== false) { $str .= $enclosure . $cell . $enclosure . $delimiter; } else { $str .= $cell . $delimiter; } } fputs($handle, substr($str, 0, -1) . "\n"); return strlen($str); } } /** * Replace get_headers() * * @category PHP * @package PHP_Compat * @link http://php.net/function.get_headers * @author Aeontech * @author Cpurruc * @author Aidan Lister * @version $Revision: 1.1 $ * @since PHP 5.0.0 * @require PHP 4.0.0 (user_error) */ if (!function_exists('get_headers')) { function get_headers($url, $format = 0) { // Init $urlinfo = parse_url($url); $port = isset($urlinfo['port']) ? $urlinfo['port'] : 80; // Connect $fp = fsockopen($urlinfo['host'], $port, $errno, $errstr, 30); if ($fp === false) { return false; } // Send request $head = 'HEAD ' . $urlinfo['path'] . (isset($urlinfo['query']) ? '?' . $urlinfo['query'] : '') . ' HTTP/1.0' . "\r\n" . 'Host: ' . $urlinfo['host'] . "\r\n\r\n"; fputs($fp, $head); // Read while (!feof($fp)) { if ($header = trim(fgets($fp, 1024))) { list($key) = explode(':', $header); if ($format === 1) { // First element is the HTTP header type, such as HTTP 200 OK // It doesn't have a separate name, so check for it if ($key == $header) { $headers[] = $header; } else { $headers[$key] = substr($header, strlen($key)+2); } } else { $headers[] = $header; } } } return $headers; } } /** * Replace function htmlspecialchars_decode() * * @category PHP * @package PHP_Compat * @link http://php.net/function.htmlspecialchars_decode * @author Aidan Lister * @version $Revision: 1.3 $ * @since PHP 5.1.0 * @require PHP 4.0.0 (user_error) */ if (!function_exists('htmlspecialchars_decode')) { function htmlspecialchars_decode($string, $quote_style = null) { // Sanity check if (!is_scalar($string)) { user_error('htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype($string) . ' given', E_USER_WARNING); return; } if (!is_int($quote_style) && $quote_style !== null) { user_error('htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype($quote_style) . ' given', E_USER_WARNING); return; } // Init $from = array('&', '<', '>'); $to = array('&', '<', '>'); // The function does not behave as documented // This matches the actual behaviour of the function if ($quote_style & ENT_COMPAT || $quote_style & ENT_QUOTES) { $from[] = '"'; $to[] = '"'; $from[] = '''; $to[] = "'"; } return str_replace($from, $to, $string); } } /** * Replace function http_build_query() * * @category PHP * @package PHP_Compat * @link http://php.net/function.http-build-query * @author Stephan Schmidt * @author Aidan Lister * @version $Revision: 1.16 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('http_build_query')) { function http_build_query($formdata, $numeric_prefix = null) { // If $formdata is an object, convert it to an array if (is_object($formdata)) { $formdata = get_object_vars($formdata); } // Check we have an array to work with if (!is_array($formdata)) { user_error('http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given.', E_USER_WARNING); return false; } // If the array is empty, return null if (empty($formdata)) { return; } // Argument seperator $separator = ini_get('arg_separator.output'); // Start building the query $tmp = array (); foreach ($formdata as $key => $val) { if (is_integer($key) && $numeric_prefix != null) { $key = $numeric_prefix . $key; } if (is_scalar($val)) { array_push($tmp, urlencode($key).'='.urlencode($val)); continue; } // If the value is an array, recursively parse it if (is_array($val)) { array_push($tmp, __http_build_query($val, urlencode($key))); continue; } } return implode($separator, $tmp); } // Helper function function __http_build_query ($array, $name) { $tmp = array (); foreach ($array as $key => $value) { if (is_array($value)) { array_push($tmp, __http_build_query($value, sprintf('%s[%s]', $name, $key))); } elseif (is_scalar($value)) { array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key), urlencode($value))); } elseif (is_object($value)) { array_push($tmp, __http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key))); } } // Argument seperator $separator = ini_get('arg_separator.output'); return implode($separator, $tmp); } } /** * Replace function ibase_timefmt() * * @category PHP * @package PHP_Compat * @link http://php.net/function.ibase_timefmt * @author Aidan Lister * @version $Revision: 1.1 $ * @since PHP 5.0.0 * @require PHP 4.0.0 (user_error) */ if (!function_exists('ibase_timefmt')) { function ibase_timefmt($format, $columntype = IBASE_TIMESTAMP) { switch ($columntype) { case IBASE_TIMESTAMP: ini_set('ibase.dateformat', $format); break; case IBASE_DATE: ini_set('ibase.dateformat', $format); break; case IBASE_TIME: ini_set('ibase.timeformat', $format); break; default: return false; } return true; } } /** * Replace idate() * * @category PHP * @package PHP_Compat * @link http://php.net/idate * @author Arpad Ray * @version $Revision: 1.2 $ * @since PHP 5.0.0 * @require PHP 4.0.0 (user_error) */ if (!function_exists('idate')) { function idate($format, $timestamp = false) { if (strlen($format) !== 1) { user_error('idate format is one char', E_USER_WARNING); return false; } if (strpos('BdhHiILmstUwWyYzZ', $format) === false) { return 0; } if ($timestamp === false) { $timestamp = time(); } return intval(date($format, $timestamp)); } } /** * Replace inet_ntop() * * @category PHP * @package PHP_Compat * @link http://php.net/inet_ntop * @author Arpad Ray * @version $Revision: 1.3 $ * @since PHP 5.1.0 * @require PHP 4.0.0 (long2ip) */ if (!function_exists('inet_ntop')) { function inet_ntop($in_addr) { switch (strlen($in_addr)) { case 4: list(,$r) = unpack('N', $in_addr); return long2ip($r); case 16: $r = substr(chunk_split(bin2hex($in_addr), 4, ':'), 0, -1); $r = preg_replace( array('/(?::?\b0+\b:?){2,}/', '/\b0+([^0])/e'), array('::', '(int)"$1"?"$1":"0$1"'), $r); return $r; } return false; } } /** * Replace inet_pton() * * @category PHP * @package PHP_Compat * @link http://php.net/inet_pton * @author Arpad Ray * @version $Revision: 1.2 $ * @since PHP 5.1.0 * @require PHP 4.2.0 (array_fill) */ if (!function_exists('inet_pton')) { function inet_pton($address) { $r = ip2long($address); if ($r !== false && $r != -1) { return pack('N', $r); } $delim_count = substr_count($address, ':'); if ($delim_count < 1 || $delim_count > 7) { return false; } $r = explode(':', $address); $rcount = count($r); if (($doub = array_search('', $r, 1)) !== false) { $length = (!$doub || $doub == $rcount - 1 ? 2 : 1); array_splice($r, $doub, $length, array_fill(0, 8 + $length - $rcount, 0)); } $r = array_map('hexdec', $r); array_unshift($r, 'n*'); $r = call_user_func_array('pack', $r); return $r; } } /** * Replace php_strip_whitespace() * * @category PHP * @package PHP_Compat * @link http://php.net/function.php_strip_whitespace * @author Aidan Lister * @version $Revision: 1.10 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) + Tokenizer extension */ if (!function_exists('php_strip_whitespace')) { function php_strip_whitespace($file) { // Sanity check if (!is_scalar($file)) { user_error('php_strip_whitespace() expects parameter 1 to be string, ' . gettype($file) . ' given', E_USER_WARNING); return; } // Load file / tokens $source = implode('', file($file)); $tokens = token_get_all($source); // Init $source = ''; $was_ws = false; // Process foreach ($tokens as $token) { if (is_string($token)) { // Single character tokens $source .= $token; } else { list($id, $text) = $token; switch ($id) { // Skip all comments case T_COMMENT: case T_ML_COMMENT: case T_DOC_COMMENT: break; // Remove whitespace case T_WHITESPACE: // We don't want more than one whitespace in a row replaced if ($was_ws !== true) { $source .= ' '; } $was_ws = true; break; default: $was_ws = false; $source .= $text; break; } } } return $source; } } /** * Replace scandir() * * @category PHP * @package PHP_Compat * @link http://php.net/function.scandir * @author Aidan Lister * @version $Revision: 1.18 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('scandir')) { function scandir($directory, $sorting_order = 0) { if (!is_string($directory)) { user_error('scandir() expects parameter 1 to be string, ' . gettype($directory) . ' given', E_USER_WARNING); return; } if (!is_int($sorting_order) && !is_bool($sorting_order)) { user_error('scandir() expects parameter 2 to be long, ' . gettype($sorting_order) . ' given', E_USER_WARNING); return; } if (!is_dir($directory) || (false === $fh = @opendir($directory))) { user_error('scandir() failed to open dir: Invalid argument', E_USER_WARNING); return false; } $files = array (); while (false !== ($filename = readdir($fh))) { $files[] = $filename; } closedir($fh); if ($sorting_order == 1) { rsort($files); } else { sort($files); } return $files; } } /** * Replace stripos() * * @category PHP * @package PHP_Compat * @link http://php.net/function.stripos * @author Aidan Lister * @version $Revision: 1.13 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('stripos')) { function stripos($haystack, $needle, $offset = null) { if (!is_scalar($haystack)) { user_error('stripos() expects parameter 1 to be string, ' . gettype($haystack) . ' given', E_USER_WARNING); return false; } if (!is_scalar($needle)) { user_error('stripos() needle is not a string or an integer.', E_USER_WARNING); return false; } if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) { user_error('stripos() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING); return false; } // Manipulate the string if there is an offset $fix = 0; if (!is_null($offset)) { if ($offset > 0) { $haystack = substr($haystack, $offset, strlen($haystack) - $offset); $fix = $offset; } } $segments = explode(strtolower($needle), strtolower($haystack), 2); // Check there was a match if (count($segments) === 1) { return false; } $position = strlen($segments[0]) + $fix; return $position; } } /** * Replace str_ireplace() * * @category PHP * @package PHP_Compat * @link http://php.net/function.str_ireplace * @author Aidan Lister * @version $Revision: 1.18 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) * @note count not by returned by reference, to enable * change '$count = null' to '&$count' */ if (!function_exists('str_ireplace')) { function str_ireplace($search, $replace, $subject, $count = null) { // Sanity check if (is_string($search) && is_array($replace)) { user_error('Array to string conversion', E_USER_NOTICE); $replace = (string) $replace; } // If search isn't an array, make it one if (!is_array($search)) { $search = array ($search); } $search = array_values($search); // If replace isn't an array, make it one, and pad it to the length of search if (!is_array($replace)) { $replace_string = $replace; $replace = array (); for ($i = 0, $c = count($search); $i < $c; $i++) { $replace[$i] = $replace_string; } } $replace = array_values($replace); // Check the replace array is padded to the correct length $length_replace = count($replace); $length_search = count($search); if ($length_replace < $length_search) { for ($i = $length_replace; $i < $length_search; $i++) { $replace[$i] = ''; } } // If subject is not an array, make it one $was_array = false; if (!is_array($subject)) { $was_array = true; $subject = array ($subject); } // Loop through each subject $count = 0; foreach ($subject as $subject_key => $subject_value) { // Loop through each search foreach ($search as $search_key => $search_value) { // Split the array into segments, in between each part is our search $segments = explode(strtolower($search_value), strtolower($subject_value)); // The number of replacements done is the number of segments minus the first $count += count($segments) - 1; $pos = 0; // Loop through each segment foreach ($segments as $segment_key => $segment_value) { // Replace the lowercase segments with the upper case versions $segments[$segment_key] = substr($subject_value, $pos, strlen($segment_value)); // Increase the position relative to the initial string $pos += strlen($segment_value) + strlen($search_value); } // Put our original string back together $subject_value = implode($replace[$search_key], $segments); } $result[$subject_key] = $subject_value; } // Check if subject was initially a string and return it as a string if ($was_array === true) { return $result[0]; } // Otherwise, just return the array return $result; } } /** * Replace strpbrk() * * @category PHP * @package PHP_Compat * @link http://php.net/function.strpbrk * @author Stephan Schmidt * @version $Revision: 1.4 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('strpbrk')) { function strpbrk($haystack, $char_list) { if (!is_scalar($haystack)) { user_error('strpbrk() expects parameter 1 to be string, ' . gettype($haystack) . ' given', E_USER_WARNING); return false; } if (!is_scalar($char_list)) { user_error('strpbrk() expects parameter 2 to be scalar, ' . gettype($needle) . ' given', E_USER_WARNING); return false; } $haystack = (string) $haystack; $char_list = (string) $char_list; $len = strlen($haystack); for ($i = 0; $i < $len; $i++) { $char = substr($haystack, $i, 1); if (strpos($char_list, $char) === false) { continue; } return substr($haystack, $i); } return false; } } /** * Replace strripos() * * @category PHP * @package PHP_Compat * @link http://php.net/function.strripos * @author Aidan Lister * @version $Revision: 1.24 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('strripos')) { function strripos($haystack, $needle, $offset = null) { // Sanity check if (!is_scalar($haystack)) { user_error('strripos() expects parameter 1 to be scalar, ' . gettype($haystack) . ' given', E_USER_WARNING); return false; } if (!is_scalar($needle)) { user_error('strripos() expects parameter 2 to be scalar, ' . gettype($needle) . ' given', E_USER_WARNING); return false; } if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) { user_error('strripos() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING); return false; } // Initialise variables $needle = strtolower($needle); $haystack = strtolower($haystack); $needle_fc = $needle{0}; $needle_len = strlen($needle); $haystack_len = strlen($haystack); $offset = (int) $offset; $leftlimit = ($offset >= 0) ? $offset : 0; $p = ($offset >= 0) ? $haystack_len : $haystack_len + $offset + 1; // Reverse iterate haystack while (--$p >= $leftlimit) { if ($needle_fc === $haystack{$p} && substr($haystack, $p, $needle_len) === $needle) { return $p; } } return false; } } /** * Replace str_split() * * @category PHP * @package PHP_Compat * @link http://php.net/function.str_split * @author Aidan Lister * @version $Revision: 1.15 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('str_split')) { function str_split($string, $split_length = 1) { if (!is_scalar($split_length)) { user_error('str_split() expects parameter 2 to be long, ' . gettype($split_length) . ' given', E_USER_WARNING); return false; } $split_length = (int) $split_length; if ($split_length < 1) { user_error('str_split() The length of each segment must be greater than zero', E_USER_WARNING); return false; } // Select split method if ($split_length < 65536) { // Faster, but only works for less than 2^16 preg_match_all('/.{1,' . $split_length . '}/s', $string, $matches); return $matches[0]; } else { // Required due to preg limitations $arr = array(); $idx = 0; $pos = 0; $len = strlen($string); while ($len > 0) { $blk = ($len < $split_length) ? $len : $split_length; $arr[$idx++] = substr($string, $pos, $blk); $pos += $blk; $len -= $blk; } return $arr; } } } /** * Replace substr_compare() * * @category PHP * @package PHP_Compat * @link http://php.net/function.substr_compare * @author Tom Buskens * @author Aidan Lister * @version $Revision: 1.5 $ * @since PHP 5 * @require PHP 4.0.0 (user_error) */ if (!function_exists('substr_compare')) { function substr_compare($main_str, $str, $offset, $length = null, $case_insensitive = false) { if (!is_string($main_str)) { user_error('substr_compare() expects parameter 1 to be string, ' . gettype($main_str) . ' given', E_USER_WARNING); return; } if (!is_string($str)) { user_error('substr_compare() expects parameter 2 to be string, ' . gettype($str) . ' given', E_USER_WARNING); return; } if (!is_int($offset)) { user_error('substr_compare() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING); return; } if (is_null($length)) { $length = strlen($main_str) - $offset; } elseif ($offset >= strlen($main_str)) { user_error('substr_compare() The start position cannot exceed initial string length', E_USER_WARNING); return false; } $main_str = substr($main_str, $offset, $length); $str = substr($str, 0, strlen($main_str)); if ($case_insensitive === false) { return strcmp($main_str, $str); } else { return strcasecmp($main_str, $str); } } } /** * Replace time_sleep_until() * * @category PHP * @package PHP_Compat * @link http://php.net/time_sleep_until * @author Arpad Ray * @version $Revision: 1.2 $ * @since PHP 5.1.0 * @require PHP 4.0.1 (trigger_error) */ if (!function_exists('time_sleep_until')) { function time_sleep_until($timestamp) { list($usec, $sec) = explode(' ', microtime()); $now = $sec + $usec; if ($timestamp <= $now) { user_error('Specified timestamp is in the past', E_USER_WARNING); return false; } $diff = $timestamp - $now; usleep($diff * 1000000); return true; } }