PDA

View Full Version : I got a tricky one...


^BuGs^
11-12-2002, 12:47 AM
I think. :D Anyone know how to take the subdomain out of a url address. :) like.... http://admin.bugssite.org/ and it takes out admin?? :)

roninblade
11-12-2002, 01:06 AM
try this...
<?php
$old_str = "http://admin.bugssite.org/";
$dot_pos = strpos($old_str, ".");
$new_str = substr($old_string, $dot_pos).substr($old_str, $dot_pos, strlen($old_str));
?>

edit: i've not tested this yet. you can also make this code block into one line like this...<?php
$new_str = substr("http://admin.bugssite.org/", strpos("http://admin.bugssite.org/", ".")).
substr("http://admin.bugssite.org/", strpos("http://admin.bugssite.org/", ".");, strlen("http://admin.bugssite.org/"));
?>

^BuGs^
11-12-2002, 02:14 AM
well... it have to remove any subdomain and then return it so I can check see if I need to make a var set to . or ..

another tricky solution is to see if a file exists if link is... http://www.bugssite.org/test.php?section=bloops

it returns that the file is not there but it does. The ?section=bloops fools around with it. :-/

Grizzly
11-12-2002, 10:20 AM
I actually might try and help you out if you obeyed any semblance of proper grammar and sentence structure. It hurts my head to try and read what the heck it is you tried to type there.

sedarious
11-12-2002, 10:58 AM
try regular expressions...

roninblade
11-12-2002, 09:03 PM
Originally posted by ^BuGs^
well... it have to remove any subdomain and then return it so I can check see if I need to make a var set to . or ..

another tricky solution is to see if a file exists if link is... http://www.bugssite.org/test.php?section=bloops

it returns that the file is not there but it does. The ?section=bloops fools around with it. :-/

gaaahh. i cant figure out what the heck you're trying to say here.

iDxMan
11-12-2002, 10:57 PM
quick hack:


<?php
$url = 'http://admin.example.com/';

if (preg_match("/^http:\/\/(\w+)\.\w+\.\w+\//", $url, $m)) {
echo "Hooray!: $m[1] ";
}

?>


^ so we know if it matches or not. If so, just use the preg_replace (http://php.net/preg_replace) function.


-r

skidooer
11-14-2002, 12:58 PM
I wouldn't say it's tricky at all!

function hostname($url)
{
$comp = parse_url($url);
return strtok($comp['host'], '.');
}