问题描述
我有一个非常奇怪的问题,无法确定。i am使用记事本++,如果我将文件保存为希腊字符(字符不是数据库)的.php,它会在网络浏览器中显示希腊字符作为问号,但如果我保存相同的字符文件为.html,则会正确显示字符。
如果从数据库显示希腊字符,则会正确显示它们,而不会出现问题。此外,我的共享托管不正常工作,但在本地主机上工作正常。
我尝试以不同的编码保存.php文件,但仍然是同一个问题。我还试图用utf-8添加php头()和元标记,但没有运气。
可能是什么问题?
谢谢
即使听起来很奇怪,您的mysql数据输出正确,php字符串编码失败,我将尝试解决您的问题的方式,将问题分解为尝试识别哪里产生这种错误的步骤!
首先,您应该尝试将您的 default_charset
设置为php.ini文件中的 utf-8
,如下所示:
default_charset =utf-8;
如果由于提供商限制而无法执行此操作,您仍然可以更改价值运行时使用功能!
您还要确保网络服务器设置为输出utf-8编码文件!在Apache中,这可以在httpd.conf中使用或使用htaccess文件:
AddDefaultCharset UTF-8
在这一点上,如果一切都失败,仍然...尝试去使用php标头和相对HTML字符集:
<?php header(content-type:text / html; charset = utf-8)?>
<!doctype>
< html>
< head>
< meta charset =utf-8>
< / head>
< body>
<?php echoαβγδεϝζηθικλνξοπϟϙρστυφχψωϡ?
< / body>
< / html>
非常重要的是,您的文件也使用适当的编码保存(utf-8几乎总是更好的选择,它有助于防止问题相当多)。如果您保存的编码不同于utf-8的文件,请将其从旧的内容中删除。有时编辑器在创建文件后不能正确地切换编码,即使记事本++一般表现良好;只需使用 converto to
而不是功能中的编码!
如果它仍然不工作,虽然我希望它现在,你可以检查一些其他PHP选项,如,,和,以解决问题!
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 characters as question marks in web browsers but if i save same characters file as .html it display characters correctly.
if Greek characters are displayed from database it show them correctly without issue. Also it is not working correctly on my shared hosting but works fine on my localhost.
i tried to save .php file in different encoding but still same issue. I also tried to add php header() and meta tags with utf-8 but no luck.
what could be the issue?Thanks
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 :
<?php header("content-type: text/html;charset=utf-8") ?>
<!doctype>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php echo "α β γ δ ε ϝ ϛ ζ η θ ι κ λ μ ν ξ ο π ϟ ϙ ρ σ τ υ φ χ ψ ω ϡ" ?>
</body>
</html>
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!
这篇关于希腊字符编码工作在HTML中,但不在PHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!