"; print_r(debug_backtrace()[1]); echo ""; } } // Begin Strings Functions here:: public static function string_position(string $string, string $needle, int $offset = 0, $encoding = null) { return F::strpos($string, $needle, $offset); } public static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) { return F::strrpos($string, $needle, $offset); } public static function string_trim($string, $charlist = null) { if (is_null($charlist)) { return F::trim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/(^[$charlist]+)|([$charlist]+$)/us", '', $string); } } public static function string_rtrim($string, $charlist = null) { if (is_null($charlist)) { return F::rtrim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/([$charlist]+$)/us", '', $string); } } public static function string_ltrim($string, $charlist = null) { if (is_null($charlist)) { return F::ltrim($string); } else { $charlist = preg_quote($charlist, '/'); return preg_replace("/(^[$charlist]+)/us", '', $string); } } public static function string_cmp($str1, $str2, $encoding = null) { return strcmp(F::strtoupper($str1, $encoding), F::strtoupper($str2, $encoding)); } /* * Case-Insensitive Find */ public static function string_first_position(string $string, string $needle, int $offset = 0, $encoding = null) { return F::stripos($string, $needle, $offset); } public static function string_sub_part(string $string, int $offset = 0, ?int $length = null, $encoding = null) { if ($length === null) { return F::substr($string, $offset, strlen($string)); } else { return F::substr($string, $offset, $length); } } /** * Not really needed as str_contains($string, $needle) now exists! * Will determine if data was found in string find and returns true if found. * @param string $data * @param string $find * @retval bool */ public static function is_string_found(string $data, string $find): bool { return (self::string_first_position($data, $find) !== false); } /** * Will get only left part of string by length. * @param string $str * @param int $length * @retval type string or false */ public static function get_string_left(string $str, int $length): false | string { return self::string_sub_part($str, 0, $length); } public static function is_json(string $maybeJSON): bool { $version = (float) phpversion(); if ($version >= 8.3) { return json_validate($maybeJSON); } else { $obj = json_decode($maybeJSON); return (json_last_error() === JSON_ERROR_NONE) ? true : false; } } /** * Will get only the right part of string by length. * @param string $str * @param int $length * @retval type string or false */ public static function get_string_right(string $str, int $length): false | string { return self::string_sub_part($str, -$length); } public static function real_time_output(): void { header("Content-type: text/plain"); // Turn off output buffering ini_set('output_buffering', 'off'); // Turn off PHP output compression ini_set('zlib.output_compression', false); // Implicitly flush the buffer(s) ini_set('implicit_flush', true); ob_implicit_flush(true); while (ob_get_level() > 0) { // Get the curent level $level = ob_get_level(); // End the buffering ob_end_clean(); // If the current level has not changed, abort if (ob_get_level() == $level) break; } } /** * Clear out from memory given variable by Reference! * @param type $sensitive_data */ public static function wipe(& $sensitive_data): void { if (function_exists("sodium_memzero")) { sodium_memzero($sensitive_data); } unset($sensitive_data); } /** * Variable Dump and exit * Configure of security for show_dumps must be true for debugging. * @param var - any type will display type and value of contents * @param bool end - if true ends the script */ public static function dump( $var = 'nothing', endDump $end = endDump::exit_and_stop ): void { if (\CodeHydrater\bootstrap\configure::get('security', 'show_dumps') !== true) { return; } // if (!is_object($var)) { var_dump($var); echo '
'; // } if ($var === false) { echo 'It is FALSE!'; } elseif ($var === true) { echo 'It is TRUE!'; } elseif (is_resource($var)) { echo 'VAR IS a RESOURCE'; } elseif (is_array($var) && self::get_count($var) == 0) { echo 'VAR IS an EMPTY ARRAY!'; } elseif (is_numeric($var)) { echo 'VAR is a NUMBER = ' . $var; } elseif (empty($var) && !is_null($var)) { echo 'VAR IS EMPTY!'; } elseif ($var == 'nothing') { echo 'MISSING VAR!'; } elseif (is_null($var)) { echo 'VAR IS NULL!'; } elseif (is_string($var)) { echo 'VAR is a STRING = ' . $var; } else { echo "
";
            print_r($var);
            echo '
'; } echo '

'; if ($end === endDump::exit_and_stop) { exit; } } public static function nl2br(string $text): string { return strtr($text, array("\r\n" => '
', "\r" => '
', "\n" => '
')); } }