正确使用PHP:header('Content-language:...'); [英] Proper use of PHP: header('Content-language: ...');

查看:103
本文介绍了正确使用PHP:header('Content-language:...');的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了明显的设置页面语言的方式:

 < meta name =languagecontent = de>< html lang =de> 

我最近发现了一个非常奇妙的方面,只有PHP的编程语言才能让开发人员设置语言在PHP文件的顶部:

 <?php 

/ * Set and pre - 定义标题中的语言;
*消除标题语言的猜测。
* /

header('Content-language:de');

?>

PHP程序员偶然会遇到两个问题:

主要问题:何时应该在PHP头文件中设置语言?



SideQ1:大型网站不打扰使用它:为什么不呢?



SideQ2:搜索引擎是否会听这个,如果是的话,这个PHP头文件有什么影响?

解决方案

较短的答案:不要打扰,导致浏览器通常忽略它。



更长的回答:W3C建议在 Content-Language lang 属性c> HTTP中的标头:



http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040808.110827800



理由:用户代理倾向于忽略标题或不一致地实现它。



另外, lang 属性更加灵活。如果您在一种语言中有一些内容,而另一种语言中有其他内容,您可以像这样精确地指定:

 < body> 
< div lang =enxml:lang =en>
< h1>欢迎!< / h1>
< p>大量英文文字...< / p>
< / div>
< div lang =frxml:lang =fr>
< h1> Bienvenue!< / h1>
< p> Beaucoup de texte enfrançais...< / p>
< / div>
< / body>

摘自:http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040728.121403792



我不知道搜索引擎。


aside the obvious fashion of setting the language of a page:

<meta name="language" content="de"><html lang="de">

I recently found an amazing aspect typical to only the programming language of PHP that could enables developers to set the language at the very top of PHP files:

<?php  

 /* Set and pre-define the language in the header;
  * Eliminating guesswork for the Header language.
  */

  header('Content-language: de');

?>

Two questions arise eveidentaly to the PHP programmer:

Main Question: When should one set the language in a PHP header?

SideQ1: Big websites don't bother using it: why don't they?

SideQ2: Do search engines listen to this and if so, what implications does this PHP header have?

解决方案

Shorter answer: Don't bother, cause browsers typically ignore it.

Longer answer: The W3C recommends using the lang attribute in HTML over the Content-Language header in HTTP:

http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040808.110827800

Rationale: User agents tend to ignore the header or implement it inconsistently.

Plus, the lang attribute is more flexible. If you have some content in one language and other in another, you can specify that precisely, like so:

<body> 
 <div lang="en" xml:lang="en">
  <h1>Welcome!</h1> 
  <p>Lots of text in English...</p>
 </div>
 <div lang="fr" xml:lang="fr">
  <h1>Bienvenue !</h1> 
  <p>Beaucoup de texte en français...</p>
 </div>
</body> 

Taken from: http://www.w3.org/International/geo/html-tech/tech-lang.html#ri20040728.121403792

I don't know about search engines.

这篇关于正确使用PHP:header('Content-language:...');的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆