Home >Backend Development >PHP Tutorial >一段PHP不能输出汉字的代码,求各位解决解决方案

一段PHP不能输出汉字的代码,求各位解决解决方案

WBOY
WBOYOriginal
2016-06-13 10:11:19915browse

一段PHP不能输出汉字的代码,求各位解决
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache"); 
include("connect.php");
ini_set("date.timezone","Asia/Shanghai");
$d1=date("Y-m-d");
$query=mysql_query("select*from item where status'完成' order by date desc ");
while($now=mysql_fetch_array($query)){
$user= "";  
$user.=" ";  
$user.=$now['serial'];
$user.= "
";
$user.=" ";  
$user.=$now['name'];
$user.= "
";
$user.=" ";  
$user.=$now['dep'];
$user.= "
";
$user.="";  
$usera=round((-strtotime($d1)+strtotime($now['completetime']))/3600/24);
if($usera$us="超期:"+abs($usera);
}
if(($usera>=0)&&($usera$us="即将到期:"+abs($usera);
}
if($usera>3){
$us="还有:"+abs($usera);
}
$user.="超期"+ $us;
$user.= "
";
$user.="";  
$user.=$now['status'];
$user.= "
";
$user.="";  
$user.=$now['percent'];
$user.= "
";
$user.="";  
$user.=$now['creator'];
$user.= "
";
$user.="";  
$user.=$now['date'];
$user.= "
";
$user.= "
";  
echo $user;
}
?>


if($usera$us="超期:"+abs($usera);
}
if(($usera>=0)&&($usera$us="即将到期:"+abs($usera);
}
if($usera>3){
$us="还有:"+abs($usera);
}
$user.="超期"+ $us;
这段代码为什么只能输出$us的数字 而前面的汉字:超期 即将到期等不能输出?

------解决方案--------------------
这不是 js ,字符串的连接应该使用. 而不是+ 
将里里面错误的地方都修改好,类似如下:

$us="即将到期:"+abs($usera);

修改成

$us="即将到期:".abs($usera);


------解决方案--------------------
这和类型转换有关。+运算符是算数的事,结果会被强制类型转换为浮点数或整数,前面的字符串自然也就不会存在。php.net手册上有讲类型转换
正确的应该使用 "超期:". abs($usera);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn