1) { if (ctype_alpha($str)) { $str[mt_rand(0, $length - 1)] = chr(mt_rand(48, 57)); } elseif (ctype_digit($str)) { $str[mt_rand(0, $length - 1)] = chr(mt_rand(65, 90)); } } return $str; } public static function reduce_slashes($str) { return preg_replace('#(? $badword) { $badwords[$key] = str_replace('\*', '\S*?', preg_quote((string) $badword)); } $regex = '('.implode('|', $badwords).')'; if ($replace_partial_words == TRUE) { $regex = '(?<=\b|\s|^)'.$regex.'(?=\b|\s|$)'; } $regex = '!'.$regex.'!ui'; if (utf8::strlen($replacement) == 1) { $regex .= 'e'; return preg_replace($regex, 'str_repeat($replacement, utf8::strlen(\'$1\'))', $str); } return preg_replace($regex, $replacement, $str); } public static function similar(array $words) { $word = current($words); for ($i = 0, $max = strlen($word); $i < $max; ++$i) { foreach ($words as $w) { if ( ! isset($w[$i]) OR $w[$i] !== $word[$i]) break 2; } } return substr($word, 0, $i); } public static function auto_link($text) { return text::auto_link_urls(text::auto_link_emails($text)); } public static function auto_link_urls($text) { if (preg_match_all('~\b(?)(?:ht|f)tps?://\S+(?:/|\b)~i', $text, $matches)) { foreach ($matches[0] as $match) { $text = str_replace($match, html::anchor($match), $text); } } if (preg_match_all('~\b(?|58;)(?!\.)[-+_a-z0-9.]++(?]*+>~im', "\n$0", $str); $str = preg_replace('~$~im', "$0\n", $str); } $str = '

'.trim($str).'

'; $str = preg_replace('~\n{2,}~', "

\n\n

", $str); if ($html_found !== FALSE) { $str = preg_replace('~

(?=]*+>)~i', '', $str); $str = preg_replace('~(]*+>)

~i', '$1', $str); } $str = preg_replace('~(?\n", $str); return $str; } public static function bytes($bytes, $force_unit = NULL, $format = NULL, $si = TRUE) { $format = ($format === NULL) ? '%01.2f %s' : (string) $format; if ($si == FALSE OR strpos($force_unit, 'i') !== FALSE) { $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); $mod = 1024; } else { $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB'); $mod = 1000; } if (($power = array_search((string) $force_unit, $units)) === FALSE) { $power = ($bytes > 0) ? floor(log($bytes, $mod)) : 0; } return sprintf($format, $bytes / pow($mod, $power), $units[$power]); } public static function widont($str) { $str = rtrim($str); $space = strrpos($str, ' '); if ($space !== FALSE) { $str = substr($str, 0, $space).' '.substr($str, $space + 1); } return $str; } }