Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Sanest method for encoding a URL
Hi there. A quick and easy question.
I’m using <txp:permlink />
to output a text string like this:
http://example.com/section/article
What I’d like to do is take that <txp:permlink />
’d URL and encode/flatten it into this format:
http%3A%2F%2Fexample.com%2Fsection%2Farticle
I was thinking I could use rah_replace
to switch the characters:
<txp:rah_replace from=":,/" to="%3A,%2F"><txp:permlink /></txp:rah_replace>
…but is there a recommended saner/cleaner option to percent encode, plugin or otherwise?
Thanks in advance.
-Pete
Last edited by gaekwad (2011-01-23 17:14:03)
Offline
Re: Sanest method for encoding a URL
Could you not use txp:php and a php snippet passing your permlink through php’s urlencode ?
Something like this (untested):
<txp:php>
global $thisarticle;
echo urlencode( permlinkurl_id($thisarticle['thisid']) );
</txp:php>
or use echo urlencode($thisarticle['url-title']);
if you just need the url_title encoded.
Alternatively, if you don’t mind using a plugin, use Jukka’s rah_function plugin to call the php command (again untested):
<txp:rah_function call="urlencode"><txp:permlink /></txp:rah_function>
BTW: Check the notes on the php docs page linked above if you have the ‘&’-sign in your urls.
Last edited by jakob (2011-01-23 18:05:20)
TXP Builders – finely-crafted code, design and txp
Offline
Re: Sanest method for encoding a URL
Thanks, jakob – very useful information :)
Offline
Pages: 1