$fileName = iconv("UTF-8", "GB2312", "抽奖记录"); header('Content-type:text/csv'); header("Content-Disposition:attachment;filename=" . $fileName . date('Y-m-d') . '.csv'); header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); header('Expires:0'); header('Pragma:public'); //标题 $title = "抽奖活动,奖品名称,用户姓名,用户OpenId,是否中奖,IP,领奖时间,过期时间,状态,抽奖时间,大区,来源\n"; echo iconv("UTF-8", "GB2312", $title); $str = ''; foreach ($list as $key => $val) { $lotteryName = iconv("UTF-8", "GBK//IGNORE", $val['LotteryName']); $itemName = iconv("UTF-8", "GBK//IGNORE", $val['ItemName']); $userName = iconv("UTF-8", "GBK//IGNORE", $val['UserName']); $openid = iconv("UTF-8", "GB2312", $val['DrawUser']); $isWin = iconv("UTF-8", "GB2312", $val['IsWin']); $ip = iconv("UTF-8", "GB2312", $val['IP']); $receiveTime = iconv("UTF-8", "GB2312", $val['ReceiveTime']); $expireTime = iconv("UTF-8", "GB2312", $val['ExpireTime']); $status = iconv("UTF-8", "GB2312", $val['StateText']); $time = iconv("UTF-8", "GB2312", $val['DrawTime']); $MU_Area = iconv("UTF-8", "GB2312", $val['MU_Area']); $laiyuan = iconv("UTF-8", "GB2312", $val['laiyuan']); $str .= $lotteryName . "," . $itemName . "," . $userName . "," . $openid . "," . $isWin . "," . $ip . "," . $receiveTime . "," . $expireTime . "," . $status . "," . $time . "," . $MU_Area. "," . $laiyuan. "\n"; } echo $str; exit; 在导出前每个字段都有数据,导出后有一条数据的laiyuan为空
时间: 2024-04-22 07:25:39 浏览: 141
用于抽奖的代码
根据你提供的代码,看起来问题可能出现在 `$val['laiyuan']` 字段的处理上。请尝试以下调整:
1. 检查 `$val['laiyuan']` 字段的值是否为空。可以在循环中使用 `var_dump($val['laiyuan'])` 来确认该字段的值是否存在。
2. 确保 `$val['laiyuan']` 字段的值是正确的编码格式。可以尝试将其转换为正确的编码格式,例如 `iconv("UTF-8", "GB2312", $val['laiyuan'])`。
3. 如果 `$val['laiyuan']` 字段的值包含特殊字符或 HTML 标签,可以尝试使用 `htmlspecialchars` 函数进行转义,例如 `$laiyuan = iconv("UTF-8", "GB2312", htmlspecialchars($val['laiyuan']))`。
确保在对字段进行处理之前,数据在数据库中是正确的。如果问题仍然存在,请提供更多关于该字段的信息,例如数据类型、示例值等,以便我能够更具体地帮助你解决问题。
阅读全文