Fix support domains with 3 levels

This commit is contained in:
Laurent Destailleur
2019-06-19 22:05:38 +02:00
parent 7c4cddf28d
commit d6b6f77e74

View File

@@ -172,14 +172,21 @@ function getURLContent($url, $postorget = 'GET', $param = '', $followlocation =
* For example: https://www.abc.mydomain.com/dir/page.html return 'mydomain'
*
* @param string $url Full URL.
* @param int $mode 0=return 'mydomain', 1=return 'mydomain.com'
* @param int $mode 0=return 'mydomain', 1=return 'mydomain.com', 2=return 'abc.mydomain.com'
* @return string Returns domaine name
*/
function getDomainFromURL($url, $mode = 0)
{
$tmpdomain = preg_replace('/^https?:\/\//i', '', $url); // Remove http(s)://
$tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after domain
$tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)$/', '\1.\2', $tmpdomain); // Remove part www.abc before domain name
if ($mode == 2)
{
$tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)\.([^\.]+)$/', '\1.\2.\3', $tmpdomain); // Remove part 'www.' before 'abc.mydomain.com'
}
else
{
$tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)$/', '\1.\2', $tmpdomain); // Remove part 'www.abc.' before 'mydomain.com'
}
if (empty($mode))
{
$tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove first level domain (.com, .net, ...)