2

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.

1
  • it depends. From where you get the domain extension? if the string only contains a domain name, parse_url() so better, otherwise preg_match(). Commented May 15, 2012 at 16:32

3 Answers 3

11

To get the domain extension use php's pathinfo

$extension = pathinfo($_SERVER['SERVER_NAME'], PATHINFO_EXTENSION);

if($extension == "de")
{
echo "this is a german site";
}

Also see: $_SERVER

Sign up to request clarification or add additional context in comments.

1 Comment

doesn't seem to work for me. I get Parse error: syntax error, unexpected T_VARIABLE
1

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.

1 Comment

I get no error at all. I don't get any messages either. I am using joomla.
0
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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.