Sign in to follow this  
Followers 0
Bogey

htmlspecialchars

10 posts in this topic

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

... 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.

Share this post


Link to post
Share on other sites

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

Edited by Bogey

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Edited by Bogey

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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']);

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0