Weird characters and question-marks in HTML instead of spaces

If your HTML pages are displaying weird symbols and/or characters before or after uploading, go through this exercise:

1. Make sure that instead of just typing all ASCII characters like quotes ( ‘ ” ` ), you use the HTML special characters ( eg. " ), here is a nice reference that I always use:

2. Something that happens a lot of times is the good old copy-and-paste bug, if you copy text from a Microsoft Word file ( .docx ) than you don’t even see anything wrong in the text, the spaces look normal in your editor, but when you serve the page there are weird characters instead. This has to do with “character-encoding”. Make sure that you saved the HTML file in the right character set and that you tell the browser which character set you are using, do this with the meta tag:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >

I recommend utf-8, but you are free to use another.

3. If the problem persists, run a find-replace in your HTML file, search out that weird character and copy it (even if it looks like a space, copy the space), and run a replace for all those characters, replace them with the HTML special characters that they are supposed to be.

Hope this helps :)

One Response to “Weird characters and question-marks in HTML instead of spaces”

  1. Abraham says:

    You could also use a php function to do the heavy lifting for you:

    function convert_bad_chars($string) {
        $search = array( chr(145), chr(146), chr(147), chr(148), chr(151));
        $replace = array( "'", "'", '"', '"', '-' );
        return str_replace($search, $replace, $string);
    $good_string = convert_bad_chars($bad_string);

Leave a Reply