0

I am extracting all the values of a table in the database to excel, but I could not set the character set to be according to utf-8. All data comes corrupted as in the screenshot below. I tried many things in line of code but couldn't find solution.

if(isset($_POST["export"])){

     $query = "SELECT * FROM memetcan";
     $result = mysqli_query($connect, $query);
     if(mysqli_num_rows($result) > 0){
          $output .= '
          <table class="table" bordered="1">  
          <tr>  
               <th>ID</th>  
               <th>Cumle</th>  
          </tr>';
          while($row = mysqli_fetch_array($result)){
               $output .= '
               <tr>  
                    <td>'.$row["sira"].'</td>  
                    <td>'.$row["cumle"].'</td>  
               </tr>
               ';
     }
     $output .= '</table>';
     header('Content-Disposition: attachment; filename=download.xls');
     header("Content-Type: application/xls; charset=utf-8");
     echo $output;
     }
}
Dharman
  • 26,923
  • 21
  • 73
  • 125

0 Answers0