[英]Check for domain extension with PHP or JS
First of all I am a php beginner so please be as specific as possible. 首先,我是一个php初学者,所以请尽可能具体。 Basically I want a php/javascript that does the following:
基本上,我想要执行以下操作的php / javascript:
if the domain has a .de extension then add the text "this is a german site" else add the text "this is not a german site" 如果域的扩展名为.de,则添加文本“这是德国站点”,否则添加文本“这不是德国站点”
it's also ok if you do it with the lang="de-DE" instead of the domain extension. 如果使用lang =“ de-DE”而不是域扩展名也可以。
In PHP, try something like this: 在PHP中,尝试如下操作:
<?php
//~ $domain = $_SERVER['HTTP_HOST'];
$domain = "domain.de";
if (preg_match('/(.*?)\.de$/', $domain)) {
echo "is german";
} else {
echo "is not german";
};
?>
Greatings. 贺礼。
var isDE="";
var extension=location.hostname.split(".");
extension=extension[extension.length-1];
if (extension=="de") isDE="this is a german site".
//do whatever you need with isDE, e.g. document.write(isDE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.