How to display special characters in PHP

前端 未结 9 1301
野的像风
野的像风 2020-11-30 12:24

I\'ve seen this asked several times, but not with a good resolution. I have the following string:

$string = \"

Résumé

\";

9条回答
  •  醉梦人生
    2020-11-30 13:03

    After much banging-head-on-table, I have a bit better understanding of the issue that I wanted to post for anyone else who may have had this issue.

    While the UTF-8 character set will display special characters on the client, the server, on the other hand, may not be so accomodating and would print special characters such as à and è as and .

    To make sure your server will print them correctly, use the ISO-8859-1 charset:

    
    
    
        
            
            Untitled Document
        
        
            
        
    
    

    This will print correctly: àè


    Edit (4 years later):

    I have a little better understanding now. The reason this works is that the client (browser) is being told, through the response header(), to expect an ISO-8859-1 text/html file. (As others have mentioned, you can also do this by updating your .ini or .htaccess files.) Then, once the browser begins to parse that given file into the DOM, the output will obey any rule but keep your ISO characters intact.

提交回复
热议问题