Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-08-23 13:05:34
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
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
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: 1,373
Re: Strip http from URL
Thanks Ruud.
Offline
#4 2008-09-08 12:28:16
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: Strip http from URL
I’ve included the above functionality in a plugin: adi_link
Offline
Pages: 1