View Single Post
Old 02-03-2010, 04:01:11 PM     #17 (permalink)
StudioVision

 
Join Date: Jan 2007
Location: Barnsley, South Yorkshire
Posts: 523
StudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond reputeStudioVision has a reputation beyond repute

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($urlPHP_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

Last edited by StudioVision; 02-03-2010 at 04:52:51 PM.
StudioVision is online now