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']); ?> Link to comment https://forums.phpfreaks.com/topic/152610-solved-apostrophes-dont-show-when-outputting-data/ 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" /> Link to comment https://forums.phpfreaks.com/topic/152610-solved-apostrophes-dont-show-when-outputting-data/#findComment-801499 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); ?> Link to comment https://forums.phpfreaks.com/topic/152610-solved-apostrophes-dont-show-when-outputting-data/#findComment-801506 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. Link to comment https://forums.phpfreaks.com/topic/152610-solved-apostrophes-dont-show-when-outputting-data/#findComment-801515 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 Link to comment https://forums.phpfreaks.com/topic/152610-solved-apostrophes-dont-show-when-outputting-data/#findComment-801523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.