Hi Guys,
Keep in mind that eregi will be deprecated as of PHP 5.3.0 and completely removed as of PHP 6
A better solution would be PHP's parse_url function
PHP Code:
$url = 'http://username:password@hostname/path?arg=value#anchor';
$parsed_url = parse_url($url); // This would return an array
print_r($parsed_url);
This would output
PHP Code:
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
If you wanted to output any of the values by themselves e.g. hostname
PHP Code:
echo $parsed_url['host'];
or you can output a single value straight from the function
PHP Code:
echo parse_url($url, PHP_URL_HOST); // This will output hostname
More info on the parse_url function can be found
here
As for the OP's problem, you would then further process the output using something like Jeewhizz's solution above.
Hope this helps!
Craig