PHP Strange character before £ sign?

后端 未结 2 1077
失恋的感觉
失恋的感觉 2021-01-25 10:57

For some reason i get a £76756687 weird character when i type a £ into a text field on my form?

2条回答
  •  没有蜡笔的小新
    2021-01-25 11:25

    You’re probably using UTF-8 as character encoding but don’t declare your output correctly. Because the £ character (U+00A3) is encoded in UTF-8 with 0xC2A3. And that byte sequence represents the two characters  and £ when interpreted with ISO 8859-1.

    So you just need to specify your character encoding correctly. In PHP you can use the header function to set the proper value for Content-Type header field like:

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

    But make sure that you call this function before any output. Otherwise the HTTP header is already sent and you cannot modify it.

提交回复
热议问题