I need to detect the language the user is using to include the correct file using PHP if elseif or else like this:
users are comming from:
example.com/EN/nice-title-url-from-database-slug
example.com/DE/nice-title-url-from-database-slug
example.com/ES/nice-title-url-from-database-slug
the php I need is something like this:
PHP
document.location.toString().split(…) etc
detect the url paths
if url path <starts with /DE/>
include de.php
elseif url <path starts with /EN/>
include en.php
else url <path starts with /ES/>
include es.php
so what I need is to detect the url after the domain (/ES/ or /EN/ or /DE/)
Any idea how to achieve this?
3
Answers
what about
?
To get the page URL, use
$_SERVER['REQUEST_URI']
. Then use explode by/
to get URL different parts.
$parts
now contain the below elements.As you can see index 1 of the
$parts
array is what you need.To achieve what we want, we need to:
So following would be my suggestion.