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

Programming and creating plugins and templates
Blog
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

Programming and creating plugins and templates
Blog
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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Global to chop http:// off URL In reply to
Thanks Andy Smile