webmaster1 Posted April 5, 2009 Share Posted April 5, 2009 Hi All, I'm outputting data from a database but apostrophes shows as '�'. The data is originally inputted through a form using mysql_real_escape_string. Does anyone know of a workaround for this? ??? OUTPUT: <?php //MYSQL QUERY mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename ORDER BY date"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); //DEFINE AS VARIABLE $newsblock=mysql_result($result,$i,"newsblock"); //PRINT VARIABLE echo"$newsblock"; ?> INPUT: <?php $newsblock = mysql_real_escape_string($_POST['newsblock']); ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted April 5, 2009 Share Posted April 5, 2009 try running $newsblock=html_entity_decode($newsblock); echo $newsblock; or check your encoding in your header. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted April 5, 2009 Author Share Posted April 5, 2009 The encoding is fine. I added your line of code but it didn't have any effect: <?php include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename ORDER BY date"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); $newsblock=mysql_result($result,$i,"newsblock"); $newsblock=html_entity_decode($newsblock); ?> Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted April 5, 2009 Author Share Posted April 5, 2009 I've tried using stripslashes but to no avail. Instead the apostrophes show as �. I can't really google this because the the � character doesn't read in the search. Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted April 5, 2009 Author Share Posted April 5, 2009 taquitosensei was 100% right actually. I changed the encoding in my header from utf-8 to ISO-8859-1. http://uk.php.net/htmlentities Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.