Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Global to chop http:// off URL

Quote Reply
Global to chop http:// off URL
Hi,

I'm changing my listings to display the site URL under the description, but I want to remove the http:// part and any trailing slash / so that http://www.qango.com/ becomes www.qango.com

Anyone got a global to achieve this?

Thanks,
Shaun
Quote Reply
Re: [qango] Global to chop http:// off URL In reply to
Hi Shaun,

This should work

sub {

my($url)=@_;
$url =~ s/http\:\/\//g;
$url=~ s/\/$//g;

$url;

}

Cheers,

Cheers,

Dat

Scripts installation and plugin creation
Plugins
Quote Reply
Re: [tandat] Global to chop http:// off URL In reply to
Hi Dat,

Thanks for the sub, however it gives the following error:

Unable to compile 'shorturl': syntax error at (eval 46) line 5, near "s/http\:\/\//g; $url=~ s/\"

Any idea what's wrong?

Cheers,
Shaun
Quote Reply
Re: [qango] Global to chop http:// off URL In reply to
Looks like a slash is missing. Try

$url =~ s/http\:\/\///g;
Quote Reply
Re: [qango] Global to chop http:// off URL In reply to
Hi Shaun,

Please just amend the first line as garrynz's post. That will work.

Cheers,

Cheers,

Dat

Scripts installation and plugin creation
Plugins
Quote Reply
Re: [tandat] Global to chop http:// off URL In reply to
Cheers guys, works a treat.

I had to modify it slightly to get the URL from the variables list, but does exactly what I want:

sub {
my $vars = shift;
my $url = $vars->{URL};
$url =~ s/http\:\/\///g;
$url=~ s/\/$//g;
return $url;
}

Thanks Smile
Shaun
Quote Reply
Re: [qango] Global to chop http:// off URL In reply to
Hi,

*little* bit cleaner :)

Code:
sub {
my $vars = shift;
my $url = $vars->{URL};

$url =~ s|\Qhttp://||g;
$url =~ s|\/$||g;

return $url;
}

Smile

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Global to chop http:// off URL In reply to
Thanks Andy Smile