Textpattern Forum

You are not logged in. Register | Login | Help

#1 2008-08-23 13:05:34

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 840
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

#2 2008-08-23 13:35:13

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 4,480
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

#3 2008-08-24 11:38:47

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 840
Website

Re: Strip http from URL

Thanks Ruud.

Offline

#4 2008-09-08 12:28:16

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 840
Website

Re: Strip http from URL

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

Offline

Board footer

Powered by FluxBB