Greek characters encoding works in HTML but not in PHP

前端 未结 1 1430
广开言路
广开言路 2020-12-18 14:04

I have very strange issue which cant figure out. i am using notepad++ and if i save a file as .php with Greek characters ( characters not from database ) it display Greek

1条回答
  •  时光取名叫无心
    2020-12-18 14:32

    Even though it sounds really strange that your mysql data is outputted correctly wheres php strings fail on encoding, the way i would try to solve your problem, would be to break down the issue into steps trying to identify where this miscoding is generated!

    First of all, you should try set your default_charset to utf-8 within the php.ini file, which is done like this :

    default_charset = "utf-8";
    

    If you can't do that because of provider restrictions you may still be able to change the value at runtime using the ini_set function!

    You'll also want to make sure that the webserver is set to output utf-8 encoded files as well! In Apache this can done both in the httpd.conf or using htaccess files :

    AddDefaultCharset UTF-8
    

    At this point if everything fails, still... try to go with php headers and relative html charset :

    
    
    
        
            
        
        
            
        
    
    

    It's very important though, that your files are saved using an appropriate encoding too (utf-8 is almost always the better choice, it helps to prevent issues quite a lot). If you saved files with encoding different than utf-8, destroy them a create new ones out of their old content. Sometimes editors aren't really able to switch encodings properly once the file is created, even though notepad++ generally does well on that; just use converto to not the encode in feature!

    If it is still not working, although i hope it does by now, you may check out some other php alternatives like mb_detect_encoding, mb_convert_encoding, htmlentities and htmlspecialchars in order to fix the problem!

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