$wordLen) { $word = substr($word, 0, $wordLen); } return $word; } /** * 获取邮箱登录地址 * 如 abc@163.com 将返回 URL http://mail.163.com/ * * @param string $mailAddress */ public static function getMailLoginUrl($mailAddress) { $mailLoginUrl = ''; $list = Zeed_Config::loadGroup('mail.login_url_list'); if ($list && ($pos = strpos($mailAddress, '@')) && $pos > 0) { $id = substr($mailAddress, $pos + 1); if (isset($list[$id])) { $mailLoginUrl = trim($list[$id]); } } return $mailLoginUrl; } public static function sleep($sec, $echoStr = '.') { $sec = (int) $sec; for ($i = 0; $i <= $sec; $i ++) { if ($echoStr) { echo $echoStr; self::flush(); } sleep(1); } } public static function println($str, $flush = true, $newline = true, $color = true) { if (isset($_SERVER['HTTP_USER_AGENT'])) { if ($newline) { $str .= '
'; } } else { if ($newline) { $str .= "\n"; } if ($color) { $str = Zeed_Console_Color::convert($str); } } echo $str; if ($flush) { self::flush(); } } /** * 刷新PHP程序的缓冲,而不论PHP执行在何种情况下(CGI ,web服务器等等)。 */ public static function flush() { if (! defined('ZEED_IN_CONSOLE') && ! headers_sent()) { echo (str_repeat(' ', 256) . "\n"); } // check that buffer is actually set before flushing if (ob_get_length()) { @ob_flush(); @flush(); @ob_end_flush(); } @ob_start(); } /** * 分割字符串 * * @param string $delimiter 分隔符,不对转义的分隔符进行分割如 \| * @param string $string 需要被分割的字符串 * @return array|false 如果定界符 $delimiter 为空字符号返回 false * @see explode() */ public static function explode($delimiter, $string) { $exploded = explode($delimiter, $string); if (is_array($exploded)) { $joinString = ''; foreach ($exploded as $id => $partString) { if (strcmp(substr($partString, - 1, 1), "\\") === 0) { $joinString .= $partString; unset($exploded[$id]); } else { if (strlen($joinString) > 0) { $exploded[$id] = $joinString . $partString; $joinString = ''; } } } } return $exploded; } /** * 获取文件后缀 * * @param string $filename * @return string 小写的文件后缀名 */ public static function fileExtension($filename) { return strtolower(substr(strrchr($filename, '.'), 1)); } } // End ^ LF ^ UTF-8