待研究
/**
* 计算字符串的长度(汉字按照两个字符计算)
*
* @param string $str 字符串
*
* @return int
*/
function str_len($str)
{
$length = strlen(preg_replace('/[\x00-\x7F]/', '', $str));
if ($length)
{
return strlen($str) - $length + intval($length / 3) * 2;
}
else
{
return strlen($str);
}
}
/**
* 获得用户操作系统的换行符
*
* @access public
* @return string
*/
function get_crlf()
{
/* LF (Line Feed, 0x0A, \N) 和 CR(Carriage Return, 0x0D, \R) */
if (stristr($_SERVER['HTTP_USER_AGENT'], 'Win'))
{
$the_crlf = '\r\n';
}
elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Mac'))
{
$the_crlf = '\r'; // for old MAC OS
}
else
{
$the_crlf = '\n';
}
return $the_crlf;
}