Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am exporting MySQL data into an Excel file which contains "Hindi" data but in place of Hindi नà¤?à¤?à¥न is appearing.

Please help in resolving my issue. My PHP code is:

<?php
    include 'connection.php';
    $filename = "currentaffairquestions";  //your_file_name
    $file_ending = "xls";   //file_extention
    mysqli_set_charset($conn,'utf8');
    header("Content-Type: application/vnd-ms-excel");    
    header("Content-Disposition: attachment; filename=$filename.xls");  
    header("Pragma: no-cache"); 
    header("Expires: 0");
    $sep = "	";
    $sql="SELECT  question_number,question_name,choice1,choice2,choice3,choice4,answer from current_affairs_question_details where id='$_GET[currentaffairid]'"; 
    $result=mysqli_query($conn,$sql);
    while ($property = mysqli_fetch_field($result)) { //fetch table field name
        echo $property->name."	";
    }

    print("
");    

    while($row = mysqli_fetch_row($result))  //fetch_table_data
    {
        $schema_insert = "";
        for($j=0; $j< mysqli_num_fields($result);$j++)
        {
            if(!isset($row[$j]))
                $schema_insert .= "NULL".$sep;
            elseif ($row[$j] != "")
                $schema_insert .= "$row[$j]".$sep;
            else
                $schema_insert .= "".$sep;
        }
        $schema_insert = str_replace($sep."$", "", $schema_insert);
        $schema_insert = preg_replace("/
|

|
|
/", " ", $schema_insert);
        $schema_insert .= "	";
        print(trim($schema_insert));
        print "
";
    }
    ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

When you're outputting the data, you need to pass it through mb_convert_encoding.

echo mb_convert_encoding($property->name, 'utf8');


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...