0

I have the following value from a field in a database that I would like to output exactly like this...

Use the term “fully accredited”-there is no such thing as a partial accreditation.

I need to include the quotes around the term "fully accredited".

Here's my output in PHP...

echo "<p><strong>Never:</strong>&nbsp;<span id=\"nevermsg\">".$results['never1']."</span></p>";

But, when I render the data on the page, it's showing these little diamond shapes with question marks inside them.

*(The 'span id' is there for styling and isn't relevant)

I don't think escaping would work here because quotes are not used in all the data values.

Not sure what to do...

Millhorn
  • 2,953
  • 7
  • 39
  • 77
  • 2
    You php code is fine. Your problem lies in database encoding. Have a look at this thread: http://stackoverflow.com/questions/6115612/how-to-convert-an-entire-mysql-database-characterset-and-collation-to-utf-8, and read this as well: http://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html (assuming mysql ofcourse) – vee Jul 26 '13 at 15:29
  • 1
    What @vinodadhikary said plus it sounds like the source text was copied from a rich text editor, such as MS Word, which uses fancy quotes and renders in a browser as strange diamond shape characters – Drew Jul 26 '13 at 15:36
  • Is there a better '&' (like you'd find in HTML) type of code I should use? It was pasted from a Word doc. Good call! – Millhorn Jul 26 '13 at 15:49

1 Answers1

1

The quotes in your string are extended characters.

You could fix this problem pretty quickly by simply replacing them with standard " quote characters rather than the curly quotes “ ” you've got now.

However, in the long term, you probably need to be able to handle extended characters, as it includes all kinds of things you're likely to need in your text, not just curly quote marks.

To fix this problem properly, you need to ensure that your system uses UTF-8 encoding at all levels. This includes within the database, your PHP code files, and the data that is sent to the browser.

I suggest reading up further on this here: UTF-8 all the way through

Community
  • 1
  • 1
Spudley
  • 166,037
  • 39
  • 233
  • 307
  • Thank you @Spudley. I just figured this out and posted the same answer below. Looks like you were answering it at the same time. I did complete a DATABASE ALTER SQL command and used UTF-8 across the board. All good now. (Erasing my answer) – Millhorn Jul 26 '13 at 16:13