0

I am getting some information like large amounts of text from the database, but while echoing using PHP, the characters are being changed. How do I get it to display the normal thing? Thanks.

//makes database connection and queries the db
$row = mysqli_fetch_array($result);
echo $row['text'];



  � inside has a question mark
\ before every apostrophe
and it\\\'s

and more...

steve
  • 31
  • 2
  • 8
  • Can you give us more examples of the bad data that it is retrieving from the database? – Wes Apr 15 '11 at 04:39
  • What character set is your database? Where is the text being inserted into the database from? What charset is your HTML page? – alex Apr 15 '11 at 04:40
  • @alex utf8 the text is being inserted by the user. – steve Apr 15 '11 at 04:44
  • UTF-8 on all counts? And by inserted, do you mean via a web form? Is the `accept-charset` different to UTF-8? – alex Apr 15 '11 at 04:47

1 Answers1

2

First up, the excessive slashes. This is generally caused by over escaping which can be due to magic_quotes, it is suggested to turn it off and use mysql_real_escape_string on the data going into the database. Before you turn it off though, make sure that the data is escaped properly, as this could introduce sql injections exploits in your site.

As far as the weird character. Your database and website character sets need to match. Make sure your website charset is set to utf-8, either with a meta tag or a header setting.

Its a hard change for the magic_quotes, but once it is done, you do not have to worry about using stripslashes on your data again. As you should not have to stripslashes on data coming out of the database, if it was escaped properly in the first place.

Jim
  • 18,673
  • 5
  • 49
  • 65