Re: Split problem...correction
| From: | Steve Edberg | Date: | Fri, 21 Jul 2000 01:58:38 +0000 |
| Subject: | Re: Split problem...correction | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-7501@lists.php.net to get a copy of this message | ||
Oops, hit 'Send' a little too hastily, before double checking what I actually wrote:
At 06:44 PM 7/20/00 , Steve Edberg wrote:
<SNIP>
Of course, in this particular example you'll get the trailing slash. For a more general approach, you could do something like (untested):So,$v = "http://www.php.net/";function get_domain_part($url, $number_of_levels) { $rval = ''; $url_parts = parse_url($url); if (is_array($url_parts) && !empty($url_parts['host'])) { $host_parts = explode('.', $url_parts['host']); $count = count($host_parts); for ($i=$count; $i > max(0,$count-$number_of_levels); $i--) # this line fixed { $rval = $host_parts[$i-1].'.'.$rval; } $rval = substr($rval, 0, -1); } return $rval; }
$v = "http://www.php.net/";
echo get_domain_part($v, 2);should produce 'php.net', and
echo get_domain_part($v, 1);should produce 'net', and so on. -steve +- Obscure computer humor, item 77: -------------------------------------+
| Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu (530)754-9127 | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |+------------------- How are cats and UNIVAC EXEC-8 similar? Fur. Purr. -+