php程序对微信昵称的表情处理,若转义存数据库,怎么读出并导出成excel文件.
<?phpinclude(dirname(__FILE__) .'/phpexcel-1.7.7/Classes/PHPExcel.php'); include(dirname(__FILE__) .'/phpexcel-1.7.7/Classes/PHPExcel/IOFactory.php');$name2 = "[[EMOJI:%F0%9F%91%BF]]李[[EMOJI:%F0%9F%8C%B9]]李[[EMOJI:%F0%9F%8D%92]]李[[EMOJI:%F0%9F%90%B0]] [[EMOJI:%F0%9F%87%A8]] [[EMOJI:%F0%9F%87%B3]] ";$name2_emoji = emoji_decode($name2);$name1_emoji = emoji_decode("汉字");//var_dump($name2_emoji);//var_dump($name1_emoji);exit;$objPHPExcel = new PHPExcel();//在激活的工作区写入数据 (单条写入数据演示)$objPHPExcel->getActiveSheet()->setCellValue('A1', $name2_emoji);$objPHPExcel->getActiveSheet()->setCellValue('A2', $name1_emoji);$objPHPExcel->getActiveSheet()->setCellValue('A3', "aa😓哈兹😀 兹");$objPHPExcel->getActiveSheet()->setCellValue('A4', "aa👏哈兹😀 兹");$objPHPExcel->getActiveSheet()->setCellValue('B1', "aa😓哈兹😀 兹");$objPHPExcel->getActiveSheet()->setCellValue('B2', "aa😓哈兹😀 兹");$objPHPExcel->getActiveSheet()->setCellValue('B3', "aa👏哈兹😀 兹");$objPHPExcel->getActiveSheet()->setCellValue('B4', "1321545 😀 兹");//写数据结束//$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);//$objWriter->save('php://output');// 将输出推到前端header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');header('Content-Disposition: attachment;filename="my_excel_sheet.xlsx"');header('Cache-Control: max-age=0');// 如果你想要打开IE的下载对话框,而不是直接下载// header('Content-Disposition: inline; filename="my_excel_sheet.xlsx"');$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save('php://output'); // 确保所有的输出被发送到客户端ob_end_flush();flush();exit();//对emoji表情转反义 function emoji_decode($str) {$strDecode = preg_replace_callback('|\[\[EMOJI:(.*?)\]\]|', function ($matches) {return rawurldecode($matches[1]);}, $str);return $strDecode; }/**对emoji表情转义* @param $nickname* @return string*/ function emoji_encode($nickname) {$strEncode = '';$length = mb_strlen($nickname, 'utf-8');for ($i = 0; $i < $length; $i++) {$_tmpStr = mb_substr($nickname, $i, 1, 'utf-8');if (strlen($_tmpStr) >= 4) {$strEncode .= '[[EMOJI:' . rawurlencode($_tmpStr) . ']]';} else {$strEncode .= $_tmpStr;}}return $strEncode; } ?>