ahmed.masri Posted April 9, 2008 Share Posted April 9, 2008 I have been trying for several days now to solve this problem. Thanks in advance for any help anyone can provide. I am trying to create a site which can be read in 5 languages. English, Arabic, German, Spanish, and Japanese. At the moment all I am doing is testing language support. I am running Windows XP Pro SP2, Apache Server, MySql, and PHP from the XAMPP installer. I also have IIS and MS SQL Express server running, but they are on different ports and are not interfering and only setup to play around with DotNetNuke (which so far I hate). My mySql database table has two fields ('LangID', 'Text'). 'Text' just has a couple of short sentences in the specified language. I used phpMyAdmin as my mySql GUI. Both fields are set to collation "utf8_bin" right now, though I have also tried "utf8_general_ci" and "utf8_unicode_ci". I can see the text, as it should appear, just fine in phpMyAdmin. I can also click on a link and print out an HTML page with the table data and this also appears as it should. I have read up on the mbString function of PHP and have tried all the tips given in at the following article all the way down through the comments: http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet. I have also tried some of the tips found in the comments at: http://dev.mysql.com/doc/refman/4.1/en/charset-connection.html. ALL TO NO AVAIL!!! .... I still get question marks instead of the right characters. the code I'm using to test printing this data is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Language Test Page</title> </head> <body> <?php /** * Encodes HTML safely for UTF-8. Use instead of htmlentities. * * @param string $var * @return string */ function html_encode($var) { return htmlentities($var, ENT_QUOTES, 'UTF-8') ; } // database connect information $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "test"; // Connect to MySql $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to MySql : mysql_error()"); // Connect to Database $db = mysql_select_db($dbname, $connect) or die("Unable to connect to Database : mysql_error()"); // SQL to retreive Data mysql_query("SET NAMES 'utf-8'"); $sql = "SELECT * FROM lang"; $result = mysql_query($sql) or die("unable to retrieve data:" . mysql_error()); while ($row = mysql_fetch_array($result)) { $lang = $row["langID"]; $text = $row["text"]; $detect = mb_detect_encoding($text, 'UTF-8, ISO-8859-1'); echo "$detect"; print ("<b>".$lang."</b><br>".$text."<br><br><br>"); } ?> <table id="table_results" class="data"> <thead><tr> <th>landID </th><th>text </th></tr> </thead> <tbody> <tr class="odd"> <td class="">English</td> <td class="">Many philosophical discussions of language begin by clarifying terminology. One item which has undergone significant scrutiny is the idea of language itself. Those philosophers who have set themselves to the task ask two important questions: "What is language in general?", and "What is a particular, individual language?".<br /><br />Some semiotic outlooks have stressed that language is the mere manipulation and use of symbols in order to draw attention to signified content. If this were so, then humans would not be the sole possessors of language skills.[45] On the other hand, many works by linguist Noam Chomsky have emphasized the role of syntax as a characteristic of any language.</td> </tr> <tr class="even"> <td class="">Arabic</td> <td class="">اللغة تميز الانسا ن عن الحيوان بحكم انها بنت الفكر .الانسان يعي ما يقول بعكس الحيوانات ولو امتلكت اعضاء النطق .بالاضافة إلى ان اللغة و الفكر يمكن اعتبارهما مرتبطان كوجهي القطعة النقديةلا يجوز فصلهما و خير مثال على دلك هو اننا نفكر ا</td> </tr> <tr class="odd"> <td class="">Español</td> <td class="">La Idea de la relatividad lingüística no era una idea original en los tiempos de Humboldt. Podía encontrarse implícita en muchas teorías sobre el lenguaje. Desde Locke que ya mantenía la tesis de la intraducibilidad de las lenguas y había sido más o menos expresada por diversos autores franceses (Condillac, Desti de Tracy, Maupertuis, de Gernado) a lo largo del siglo XVIII. Pero sólo en Humboldt adquiere la tesis de la relatividad lingüística la función de núcleo central de toda una teoría sobre el lenguaje y sobre el hombre. Sólo a partir de su obra el relativismo se convierte en un tema recurrente.</td> </tr> <tr class="even"> <td class="">Deutsch</td> <td class="">Wer spricht, der stellt nicht nur etwas dar, der tut etwas. Diese Erkenntnis hat John Langshaw Austin in einer Vorlesungsreihe im Jahre 1955 formuliert (1962 als How To Do Things With Words publiziert). Austin unterscheidet in der Folge zwischen einem lokutionären, einem illokutionären und einem perlokutionären Akt, vereinfachend gesagt zwischen dem, was mit der Äußerung gesagt wird, was mit ihr getan wird und was mit ihr bewirkt wird. Wenn zum Beispiel jemand äußert "Schiess dieses Tier nieder!", dann hat er damit gesagt, dass die angesprochene Person das Tier niederschießen soll (Lokution), er hat ihr geraten oder befohlen, das Tier niederzuschießen (Illokution) und er hat sie (unter Umständen) überzeugt, dass sie das Tier niederschießen soll (Perlokution).</td> </tr> <tr class="odd"> <td class="">Japanese</td> <td class="">彼に拠れば、人間は、現実の諸言語を創造する能力とこれらの諸言語を規定する言語形式保持の能力とをもつ。後者からの外部表出としての前者が多様に具現化することを以って、人間の諸言語の(フンボルトの思想によれば)ひいては人間の諸文化・思想の多様性を説明しようとした。ただし、当時の言語学者は主に個別言語に興味を有しており、また、哲学者たちは人間精神自身の能力に関心を持っていたため、フンボルトの影響は限定的なものにとどまった。</td> </tr> </tbody> </table> </body> </html> The following lines are slightly revealing: $detect = mb_detect_encoding($text, 'UTF-8, ISO-8859-1'); echo "$detect"; They tell me that the languages are being printed out in 'UTF-8' encoding, except for Spanish and German which print out in 'ISO-8859-1'. Please help me out if you have any idea on where I may be going wrong. I'm at my wits end. Thanks again in advance. Link to comment https://forums.phpfreaks.com/topic/100395-multiple-languages-on-the-same-page-extracted-from-mysql/ Share on other sites More sharing options...
ahmed.masri Posted April 10, 2008 Author Share Posted April 10, 2008 I figured it out! I changed the line mysql_query("SET NAMES 'utf-8'") to: mysql_query("SET NAMES 'utf8'") and all is working.. i can't believe no one saw that! Link to comment https://forums.phpfreaks.com/topic/100395-multiple-languages-on-the-same-page-extracted-from-mysql/#findComment-513652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.