Fix incorrectly displayed encoding on an html document with php

前端 未结 4 969
半阙折子戏
半阙折子戏 2020-12-01 17:34

Is there a way to fix the characters that display improperly after running this html markup through phpquery::newDocument? There are slated double quotes around -Classics wi

相关标签:
4条回答
  • 2020-12-01 18:01
    1. You need to save the page with UTF-8 without BOM encoding.
    2. Add this header on top of your script:

      header("Content-Type: text/html; charset=UTF-8");

    [EDIT]: How to Save Files as UTF-8 without BOM :

    On OP request, here's how you can do on Windows:

    1. Download Notepad++. It is an awesome text-editor that you should be using.
    2. Install it.
    3. open the PHP script in Notepad++ that contains this code. The page where you are doing all the coding. Yes, that file on your computer.
    4. In Notepad++, from the Encoding menu at the top, select "Convert to UTF-8 without BOM".
    5. Save the file.
    6. Upload to your webserver by FTP or whatever you use.
    7. Now, run that script.
    0 讨论(0)
  • 2020-12-01 18:03

    i had the same problem but when i added

    ob_start();
    

    to first line

    ob_end_flush();
    

    to the end it seem to be working

    0 讨论(0)
  • 2020-12-01 18:07

    I had same problem using phpQuery class. Problem IS as mentioned above, in top voted answer - script file is saved as UTF8-with BOM.

    As i had no no chance getting notepad++ on mac osX,

    every output i prepared like this utf8_decode()

    BOM is meant for MS-windows.

    0 讨论(0)
  • 2020-12-01 18:12

    You have this in the <head> element:

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

    The next course would be to use HTML entities to display these characters.

    0 讨论(0)
提交回复
热议问题