Hi guys.

When I fetch text from my database and try to echo it on the front end of my (client's) website, I keep getting a black diamond shaped symbol with a question mark inside it.

After I searched the net for help, I found a solution that seemed to work.

The problem was regarding this tag:

<meta charset="utf-8">

...... which is what comes with with the bootstrap template ( by default ).

And on the forum it explained how I should use this line:

<meta http-equiv="Content-Type" content="text/html; charset=iso-859-1">

So I replaced it with the above line and it now works without any black diamonds appearing.

But I have slight reservations about using the above recommended line, as I live in England.

I was under the impression that you have to use a certain line depending on where you line in the world?

I guess what i am trying to ask is: is:

<meta http-equiv="Content-Type" content="text/html; charset=iso-859-1">

... ok for me to use no matter where I live in the world?

Or could it harm my client's website (in regards to SEO, etc, etc, etc)?

    Just want to point out that you mean ISO-8859-1; see https://en.wikipedia.org/wiki/ISO/IEC_8859-1. If you're not going to support any script outside what's listed there, then you should be good to go.

    It's important that the character set you claim to use is the same as the character set you actually use - failure to do that is what leads to wonky-looking text like [font=monospace]&#65533;[/font] or [font=monospace]“double quoted textâ€[/font]. Like NogDog, I prefer using UTF8 (including source code files, because the file's encoding applies to string literals in the code) since I do have a nonvanishing need to support M&#257;ori.

      Thanks guys.

      After examing the database and the specific field values I am fetching from the database, I have spotted that the collation of my varchar fields is: latin1_swedish_ci,,,, and when I log in to the database (phpmyAdmin) it says 'server connection collation' with 'utf8_general_ci' selected.

      Like I said above,,, The default character set on my pages is <meta charset="utf-8">

      So, would changing latin1_swedish_ci,,,, and utf8_general_ci fix my problem??

      And if so, what would I change them to??

      Paul.

        3 months later

        Hi guys.

        I am having the same problem again.

        I can't even echo out the '£' sign without getting the little black diamond displaying.

        I am using 'wamp' as my localhost to generate my php code and the charset of my php doc is: <meta charset="utf-8"> ...... This is the default charset that came with my bootstrap starter template, when I downloaded bootstrap.

        This is so confusing and I am totally lost!!

        Please explain how I can fix this in laymen's terms.

        I am from the UK, so I don't know if I am having this character issue due to the country I am in.

        Please help me.

        Paul.

          First thing I'd try is to add a php header() call, to ensure your web server is not sending a problematic HTTP header. This needs to be called before any output is sent to the browser.

          <?php
          header('Content-Type: text/html; charset=UTF-8');
          

            It also helps if the text you're sending is also using the same encoding as everything else. If it is coming from string literals in your PHP source code, then the files need to be saved as UTF-8 so that the string literals are recorded in the file with that encoding. If it is stored as character data in the database, then that needs the right encoding as well.

              And if saving your PHP file as UTF-8, make sure that BOM (Byte Order Mark) is not enabled, as that can cause output to be sent to the browser, which can then muck up all sorts of things. 🙂

                Write a Reply...