How to set UTF-8 encoding for a PHP file

后端 未结 7 1447
-上瘾入骨i
-上瘾入骨i 2020-11-28 08:24

I have a PHP script called :

http://cyber-flick.com/apiMorpho.php?method=getMorphoData&word=kot

That displays some data in p

相关标签:
7条回答
  • 2020-11-28 08:54

    Also note that setting a header to "text/plain" will result in all html and php (in part) printing the characters on the screen as TEXT, not as HTML. So be aware of possible HTML not parsing when using text type plain.

    Using:

    header('Content-type: text/html; charset=utf-8');
    

    Can return HTML and PHP as well. Not just text.

    0 讨论(0)
  • 2020-11-28 08:56

    You have to specify what encoding the data is. Either in meta or in headers

    header('Content-Type: text/plain; charset=utf-8');
    
    0 讨论(0)
  • 2020-11-28 09:03

    Try this way header('Content-Type: text/plain; charset=utf-8');

    0 讨论(0)
  • 2020-11-28 09:05

    Html:

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta name="x" content="xx" />
    

    vs Php:

    <?php header('Content-type: text/html; charset=ISO-8859-1'); ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta name="x" content="xx" />
    
    0 讨论(0)
  • 2020-11-28 09:07

    PHP, by default, always returns the following header: "Content-Type: text/html" (notice no charset), therefore you must use

    <?php header('Content-type: text/plain; charset=utf-8'); ?>
    
    0 讨论(0)
  • 2020-11-28 09:08
    header('Content-type: text/plain; charset=utf-8');
    
    0 讨论(0)
提交回复
热议问题