Home >Backend Development >PHP Tutorial >Easily implement PHP output excel_PHP tutorial
To output PHP data to an excel table, PHP has very good support in this regard. PHP can output a simple excel table with just a few simple sentences.
PHP code:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=users.xls" );
echo "Company name"." ";
echo "Username"." ";
echo "password"." ";
echo "second-level domain name"." ";
echo " ";
foreach($result[result] as $val){
echo "$val->ComName"." ";
echo "$val->UserName"." ";
echo "$val->UserTruePw"." ";
echo emptyempty($val->DoMainName)?:(http://.$val->DoMainName..jiaomai.com)." ";
echo " ";
}
?>
Pay attention to encoding issues, because tables are generally output in UTF-8 encoding. When I output it in tabular format (table+tr+td), garbled characters appear. . . . Because the encoding of my page is GB2312, I can use iconv to convert it. In order to prevent the garbled code from being messed up by myself, it is best to use the above method to output.