Bogey Posted April 10, 2012 Share Posted April 10, 2012 Hi all, I have this in a cell in my mysql-database: 'René' When I extract it from SQL with PHP and show it in my HTML page, then I dont get the é!I get a square with a questionmark in it... How can I manage it, so it shows the é? I tried it with htmlspecialchars, but did not get it right :S Thnx Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2012 Share Posted April 10, 2012 The PHP files need to be saved using UTF-8, all pages involved need to have a content-type of UTF-8, and the database needs to use a collation of UTF-8. Link to comment Share on other sites More sharing options...
boen_robot Posted April 11, 2012 Share Posted April 11, 2012 ... and the MySQL connection needs to specify UTF-8 as a charset with mysqli::set_charset(), and if you use htmlspecialchars (as the title of the topic implies), you must specify that in the third argument of htmlspecialchars. Link to comment Share on other sites More sharing options...
Bogey Posted April 12, 2012 Author Share Posted April 12, 2012 Ok, this I have now:php-files saved UTF-8;the particular row in the database has collation ' utf8_general_ci '; this is in my code: include($_SERVER['DOCUMENT_ROOT'].'/config.php');$link = mysqli_connect('localhost',$GLOBALS['dbuser'],$GLOBALS['dbpass']) or die(mysql_error());mysqli_set_charset($link,"utf8"); <H2><?php echo htmlspecialchars($row['naam'],ENT_QUOTES,'UTF-8');?></H2> It has to echo René, but it echoes Ren Link to comment Share on other sites More sharing options...
boen_robot Posted April 12, 2012 Share Posted April 12, 2012 Also add header('Content-Type: text/html;charset=UTF-8'); Somewhere at the top (before any echoes). That's the "all pages involved need to have a content-type of UTF-8" part. Link to comment Share on other sites More sharing options...
Bogey Posted April 14, 2012 Author Share Posted April 14, 2012 Can't get it done! :S In database cell is filled: 'René'Cell has a coallition "utf8_general_ci" Piece of template file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>{CMS:TITLE}</TITLE><META http-equiv="X-UA-Compatible" content="IE=8" /><META http-equiv="Content-Type" content="text/html; charset=utf-8" /><META http-equiv="Content-Language" content="nl" /><META name="description" content="{CMS:DESCRIPTION}" /><META name="keywords" content="{CMS:KEYWORDS}" />{CMS:BASETAG} Piece of code in php: <?phpinclude($_SERVER['DOCUMENT_ROOT'].'/config.php'); //Include de config met username en passwords//mysql_connect('localhost',$GLOBALS['dbuser'],$GLOBALS['dbpass']) or die(mysql_error());$link = mysqli_connect('localhost',$GLOBALS['dbuser'],$GLOBALS['dbpass']) or die(mysql_error());//mysql_select_db($GLOBALS['dbname']); //mysqli_connect('localhost',$GLOBALS['dbuser'],$GLOBALS['dbpass']) or die(mysql_error());// mysqli_select_db($GLOBALS['dbname']);// mysqli_set_charset($link, "utf8");// mysqli_set_charset($link,"utf8");// mysqli::set_charset('utf8'); mysqli_set_charset($link, "utf8")header ('Content-Type: text/html;charset=UTF-8');?><DIV class='inputContainerLabel'><LABEL for='selectNaam'>Naam:</LABEL><SELECT style='width:100px;' id='selectNaam' name='selectNaam' onchange="checkAllSelected_Omschrijving()"><OPTION value=empty>selecteer:</OPTION><?php$result = mysql_query("SELECT * FROM opmerkingen_users ORDER by naam");$options="";while ($row= mysql_fetch_array($result)) {$options.='<OPTION value ="' . htmlspecialchars($row['naam'],ENT_QUOTES,'UTF-8') . '">' . htmlspecialchars($row['naam'],ENT_QUOTES,'UTF-8').'</OPTION>';}echo $options;?></SELECT></DIV> I tried different options, but can't get it done :S What do I wrong, or what am I missing? Link to comment Share on other sites More sharing options...
Bogey Posted April 14, 2012 Author Share Posted April 14, 2012 When I use mysql, then I get the info from DB, but not the right way... looking at é! When I use mysqli, I cant get info from DB.... :S When use mysqli, then also use mysqli_query? or isn't that a existing command? Link to comment Share on other sites More sharing options...
boen_robot Posted April 14, 2012 Share Posted April 14, 2012 Wait... what's with this template thing?The line header('Content-Type: text/html;charset=UTF-8'); needs to appear before this template outputs anything... ideally, even before you call the template engine.Plus, this template system itself might need a setting somewhere in it too, leading to the mess up in the absence of that setting.To ensure it's not the template system's fault, just for the sake of testing, run only the "Piece of code in php" part.As for MySQLi... I see a syntax error here: mysqli_set_charset($link, "utf8") you're missing the semicolon.Also, you haven't replaced all MySQL functions with the MySQLi equivalents, and finally, you do need mysqli_select_db($GLOBALS['dbname']); Link to comment Share on other sites More sharing options...
Bogey Posted April 15, 2012 Author Share Posted April 15, 2012 when I run this code in a new php file, and just browse to that single php file, then it all goed well... <?phpinclude($_SERVER['DOCUMENT_ROOT'].'/config.php'); //Include de config met username en passwordsmysql_connect('localhost',$GLOBALS['dbuser'],$GLOBALS['dbpass']) or die(mysql_error());mysql_select_db($GLOBALS['dbname']);?><DIV class='inputContainerLabel'><LABEL for='selectNaam'>Naam:</LABEL><SELECT style='width:100px;' id='selectNaam' name='selectNaam' onchange="checkAllSelected_Omschrijving()"><OPTION value=empty>selecteer:</OPTION><?php$result = mysql_query("SELECT * FROM opmerkingen_users ORDER by naam");$options="";while ($row= mysql_fetch_array($result)) {$options.='<OPTION value ="' . $row['naam'] . '">' . $row['naam'].'</OPTION>';}echo $options;?></SELECT></DIV> When I call that file in the template, then its not going fine :S So it has to be something with the template... I go look further on that one Link to comment Share on other sites More sharing options...
Bogey Posted April 15, 2012 Author Share Posted April 15, 2012 Think it hasn't be something with template, but has something to do with the CMS....I just emailed my friend, who has made the CMS, hope he knows the sollution I come back to this one Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.