Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

perl question [OT]

General discussions related to php

Moderators: macek, egami, gesf

perl question [OT]

Postby leon » Thu Oct 31, 2002 3:45 am

sorry a question about perl ..

this line

my ($newhost) = $ENV{'HTTP_HOST'};

returns

http://www.mydomain.com

but on my $newhost i need only mydomain.com without "www."


What can I do , my perl experience is very low , anyone can help me ?

Thanks !!!
User avatar
leon
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am

Postby leon » Thu Oct 31, 2002 6:45 am

anyone , or at least where can I find a perl forum ?

thanks
User avatar
leon
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am

Re: perl question [OT]

Postby jstrellner » Wed Nov 06, 2002 11:33 am

leon wrote:sorry a question about perl ..

this line

my ($newhost) = $ENV{'HTTP_HOST'};

returns

http://www.mydomain.com

but on my $newhost i need only mydomain.com without "www."


What can I do , my perl experience is very low , anyone can help me ?

Thanks !!!


You can replace your code with the following code. It is untested but it should work.

Code: Select all
my ($newhost) = $ENV{'HTTP_HOST'};

if ($ENV{'HTTP_HOST'}=~/^www./) {
   $newhost =~ s/www.//g;
}


Hope that this helps. What it is actually doing is checking to see if there is a "www." at the begining and if there is it removes it.

Sorry, the first method will remove the last "www." in the $new host field. Usually this will work however if you run into http://www.mywww.com it will return http://www.mycom. So use the method below, it checks if it exists and if it does it removes the first 4 characters from the begining.

Code: Select all
if ($ENV{'HTTP_HOST'}=~/^www./) {
   $hostlength = length ($ENV{'HTTP_HOST'});
   $newhost = substr($ENV{'HTTP_HOST'}, 3, $hostlength);
}


The code above will also create the $newhost variable and replace your line of code:

Code: Select all
my ($newhost) = $ENV{'HTTP_HOST'};


Hope that this helps
jstrellner
New php-forum User
New php-forum User
 
Posts: 6
Joined: Tue Nov 05, 2002 11:05 pm
Location: Las Vegas, NV

Postby leon » Thu Nov 07, 2002 6:23 am

T H A N K Y O U !
User avatar
leon
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Aug 03, 2002 11:54 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron