Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-15 16:26:28

Sam
Member
From: New York City
Registered: 2004-06-26
Posts: 127
Website

How do I parse a URL that is stored in a custom field?

Hey,

Over at Posh CSS I currently store the links to the full articles in a custom field:

<txp:custom_field name="fullurl" />

How do I then convert that value from say: http://www.zurb.com/article/305/easily-turn-your-images-into-polaroids-wi to just zurb.com for easy display on my site?

I currently have a second field that is titled shorturl, but surely there is a way to convert the original URL using the parse_url function in PHP? I only need the hostname.

My ideal output would be:

<a href="<txp:custom_field name="fullurl" />">***parsed hostname here***</a>

This one is a little over my head, any advice?

Thanks.

Offline

#2 2009-10-15 16:48:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,454
Website GitHub

Re: How do I parse a URL that is stored in a custom field?

Sam wrote:

How do I then convert that value… to just zurb.com for easy display on my site

Someone (Gocom?) told me that parse_url() is quite slow, so a combination of string functions might be quicker; especially in a list situation:

<a href="<txp:custom_field name="fullurl" />">
<txp:php>
   $str = custom_field(array('name' => 'fullurl'));
   echo substr($str, 0, strpos($str, '/', 8));
</txp:php>
</a>

(untested) but it’ll fail if there’s a URL without any /section/article after it so be careful that your custom fields are all individual articles.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-10-15 18:00:33

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,732
Website

Re: How do I parse a URL that is stored in a custom field?

nice and simple, stef.

off-topic: just a heads-up sam. I have tried to reach welovetxp.com on and off over the past few weeks with no luck – it always times out for me (the google cache links too). Is it just me or is it currently down?

edit: your other links in your signature are also unreachable, but PoshCSS is no problem.

Last edited by jakob (2009-10-15 18:02:07)


TXP Builders – finely-crafted code, design and txp

Offline

#4 2009-10-15 18:06:12

Sam
Member
From: New York City
Registered: 2004-06-26
Posts: 127
Website

Re: How do I parse a URL that is stored in a custom field?

Thanks Stef, that helps a lot! :)

Jakob, nope everything is running fine as far as I can tell. Normal to good traffic levels. That said, someone else had problems visiting my personal site. sam.brown.tc, is that the case for you as well?

Could you provide a traceroute to welovetxp.com for me and I’ll submit it to my host.

Offline

#5 2009-10-15 20:01:56

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,732
Website

Re: How do I parse a URL that is stored in a custom field?

traceroute duly sent via board email.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB