I get an error in PHP excel utf8 -
i utf 8 character error when exporting excel though codes way. have changed since iso-8859-9 have not changed yet. keep getting character error "ü,Ü,ş,i,Ç,ğ"
<?php /*******edit lines 3-8*******/ mysql connection //create mysql connection $sql = "select * users"; $connect = @mysql_connect($db_server, $db_username, $db_password) or die("couldn't connect mysql:<br>" . mysql_error() . "<br>" . mysql_errno()); //select database $db = @mysql_select_db($db_dbname, $connect) or die("couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); //execute query $result = @mysql_query($sql,$connect) or die("couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $file_ending = "xls"; //header info browser header("content-encoding: utf-8"); header("content-type: application/xls; charset=utf-8"); header("content-disposition: attachment; filename=$filename.xls"); header("pragma: no-cache"); header("expires: 0"); /*******start of formatting excel*******/ //define separator (defines columns in excel & tabs in word) $sep = "\t"; //tabbed character //start of printing column names names of mysql fields ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); //end of printing column names //start while loop data while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_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("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?>
Comments
Post a Comment