Writing A Word Document With Proper Char Encoding

Discussion in 'PHP' started by timallard, Oct 20, 2009.

  1. #1
    Hi all,

    I am generating a word doc on page load, it saves fine, but when I open it in msword a dialog popsm up asking me which encoding i would like for my text.

    Can i build this into my script to pick the charset automatically?

    
    
    
    
    
    <?php $docOut .= "Search Results Export"; ?>
                            <?php $docOut .= "\n"; ?>
    						<?php $docOut .= "Exported: " . number_format($num_rows[0]) . " results."; ?>
                            <?php $docOut .= "\n"; ?>
    						<?php $docOut .= "By: " . $_SESSION['firstName'] . " " . $_SESSION['lastName']; ?>
                            <?php $docOut .= "\n"; ?>
                            <?php $docOut .= "Date:" . " " . $dateToday; ?>
                            <?php $docOut .= "\n"; ?>
                            <?php $docOut .= "\n"; ?>
    
    //THE ROWS OF DATA THAT GET LOOPED
    
    $docOut .= "\n";
    							$docOut .= "____________________________";
    							$docOut .= "\n";
    							$docOut .= "\n";
    							$docOut .= "Name: " . $row1['FirstName'] . " " . $row1['LastName'];
    							$docOut .= "\n";
    							$docOut .= "Town: " . $row1['Town']; 
    							$docOut .= "\n";
    							$docOut .= "Date: " . $row1['DateStamp']; 
    							$docOut .= "\n";
    							$docOut .= "Category: " . $row1['Category']; 
    							$docOut .= "\n";
    							$docOut .= "\n";
    							$docOut .= "Curiosity: " . $row1['Curiosity']; 
    							$docOut .= "\n";
    
    //// WRITING OF THE FILE
    
    
    $exportPathdoc = 'data/exports/search-results/search-results-' . $dateToday . '.doc';
    							$fdoc = fopen ($exportPathdoc,'w');
    							fputs($fdoc, $docOut);
    							fclose($fdoc);
    
    
    
    
    
    please help :)
    
    
    PHP:

     
    timallard, Oct 20, 2009 IP
  2. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #2
    anyone? im stumped...
     
    timallard, Oct 21, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    necessary bump, >.<
     
    timallard, Oct 23, 2009 IP
  4. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    did u try to set encoding to charset = utf-8?
     
    xenon2010, Oct 23, 2009 IP
  5. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #5
    I am not sure how to do that in my php code, any ideas?
     
    timallard, Oct 23, 2009 IP
  6. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    put this code inside your file in the top between head tags..
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    PHP:
    if not working then try to add inside your outputted file like:

    $docOut .= '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
    $docOut .= "Search Results Export";
    ..............................
    ....................
    ............
    the rest of your codes 
    .......
    
    PHP:
     
    xenon2010, Oct 23, 2009 IP