Red wrote: > hello, im not a php developer, i just need to rewrite one php file but having problem with understanding syntax of regexp in php. > > i need to get domain name from fqdn (for example from $_SERVER['HTTP_HOST'] ) > > in sed its working well with "s/[^.]*\.//" , but preg_replace behaves weird. > > > http_host is for example hostname.domain.com > > <?php > $host = $_SERVER['HTTP_HOST']; > exec( "echo $host | sed s/[^.]*\.//", $domain ) ; > echo "$domain[0]" > ?> > > return "domain.com", but > > <?php > $host = $_SERVER['HTTP_HOST']; > $domain = preg_replace( '/[^.]*\./' , '', $host) ; > echo "$domain"; > ?> > > return only "com" > > i think when this php page get many hits, its not so wise to call sed everytime, i would like to ask someone for help how to write preg_replace pattern. > > thanx > > Rene > I would add one thing and change another. <?php $host = $_SERVER['HTTP_HOST']; $domain = preg_replace( '/^[^.]+\./' , '', $host) ; echo $domain; ?> Adding an additional '^' to the start tells it to start at the beginning. And changing '*' to a '+' Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php