Check for domain extension with PHP or JS
-
09-06-2021 - |
Question
First of all I am a php beginner so please be as specific as possible. Basically I want a php/javascript that does the following:
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"
it's also ok if you do it with the lang="de-DE" instead of the domain extension.
OTHER TIPS
In PHP, try something like this:
<?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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow