2008-08-23 13:05:34

gomedia
Plugin Author
omicron
Real name: Adi
Website

Strip http from URL

Short of writing a plugin, does anyone have any ideas how to strip “http://” & a trailing slash from a URL?

For example a URL stored, say, in a custom field as “http://www.websitename.com/” would be output as “www.websitename.com”.

A plugin might do it as follows:

<txp:strip_http><txp:custom_field name=“link” /></txp:strip_http>

Thanks,

Adi

Offline

 

2008-08-23 13:35:13

ruud
Developer emeritus
omega
Real name: Ruud van Melick
From: a galaxy far far away
Known languages: li,nl,en,(de)
Website

Re: Strip http from URL

<txp:php>
  echo preg_replace('#^(?:http://)?(.*?)/?$#', '$1', custom_field(array('name' => 'link')));
</txp:php>

or:

<txp:php>
  echo rtrim(str_replace('http://', '', custom_field(array('name' => 'link'))), '/');
</txp:php>

Last edited by ruud (2008-08-23 13:37:35)

Offline

 

2008-08-24 11:38:47

gomedia
Plugin Author
omicron
Real name: Adi
Website

Re: Strip http from URL

Thanks Ruud.

Offline

 

2008-09-08 12:28:16

gomedia
Plugin Author
omicron
Real name: Adi
Website

Re: Strip http from URL

I’ve included the above functionality in a plugin: adi_link

Offline

 

Powered by FluxBB