Forum Moderators: coopster

Message Too Old, No Replies

Domain filter problem

         

asantos

9:52 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



If i have this
$test = 'subdomain.some-other-subdomain.mydomain.com';
or
$test = 'subdomain.mydomain.com';
or
$test = 'mydomain.com';

it must return
'mydomain.com';

Any ideas? Thanks.

Psychopsia

12:50 am on Aug 30, 2006 (gmt 0)

10+ Year Member



Try this function:

$url_info = parse_url($url);

[edited by: Psychopsia at 12:51 am (utc) on Aug. 30, 2006]

asantos

3:13 am on Aug 30, 2006 (gmt 0)

10+ Year Member



that wont work because

$url = "http://somesubdomain.someotherstuff.abc.com/somedir";
$data = parse_url($url);
echo $data['host'];

will print:
somesubdomain.someotherstuff.abc.com

Psychopsia

4:21 am on Aug 30, 2006 (gmt 0)

10+ Year Member



Try my new function:

<?php

$url = "http://somesubdomain.someotherstuff.abc.com/somedir";
$data = parse_domainname($url);
print_r($data);

function parse_domainname($url)
{
if (preg_match('#([a-z]+)://(.*?)\.(.*?)\.(.*?)\.([a-z]+)#is', $url, $data))
{
// http://a.b.domain.com /path
return $data;
}
else if (preg_match('#([a-z]+)://(www\.)?(.*?)\.(.*?)\.([a-z]+)#is', $url, $data))
{
// http://a.domaim.com /path
// http://www.a.domain.com /path
return $data;
}
else if (preg_match('#([a-z]+)://(www\.)?(.*?)\.([a-z]+)#is', $url, $data))
{
// http://domain.com /path
// http://www.domain.com /path
return $data;
}
}

?>

dreamcatcher

7:02 am on Aug 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo substr($test,strpos($test,'mydomain'));

dc

asantos

11:05 pm on Aug 30, 2006 (gmt 0)

10+ Year Member



Psychopsia
that doesnt seem to work.

dreamcatcher
the point is, i do not know the value of mydomain.

Psychopsia

12:16 am on Aug 31, 2006 (gmt 0)

10+ Year Member



I tested it with all the combinations in your example.

Which is your result of the array, returned by the function?

The preg_match in the function removes the string after tld (.com)

* My returned array is:

Array ( [0] => [somesubdomain.someotherstuff.abc.com...] => http [2] => somesubdomain [3] => someotherstuff [4] => abc [5] => com )

[1][edited by: Psychopsia at 12:18 am (utc) on Aug. 31, 2006]

asantos

12:49 am on Aug 31, 2006 (gmt 0)

10+ Year Member



Psychopsia,
actually i accomplished to solve my problem with this other simpler function:

$url = parse_url('http://subdomain.somehost.com');
$url = explode('.',$url['host']);
if(count($url)>1) {
$url = $url[count($url)-2];
} else {
$url = $url[0];
}
echo $url; //this prints "somehost"

It works with in all cases, even in "localhost"