We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: URLSafe

Development and Programming

Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

Makes a string url safe. Or the reverse. I needed to use this for some friendly category names in a url a while back. With the release of EE 1.6, this might be obsolete, but hey, it might come in handy somewhere as well.

This is a pretty basic plugin. Underscores are replaced with a comma and a space, and hyphens are replaced with spaces.

Place the following tag in any of your templates:

{exp:urlsafe}Sides, Soups, Salads{/exp:urlsafe}
Returns: sides-soups-salads

{exp:urlsafe reverse="yes"}sides_soups_salads{/exp:urlsafe}
Returns: Sides, Soups, Salads

{exp:urlsafe reverse="yes"}sides-soups-salads{/exp:urlsafe}
Returns: Sides Soups Salads

PARAMETERS: The tag has two (optional) parameters:

  1. separator: The replacement character [OPTIONAL, defaults to hyphen ‘-‘]
  2. reverse: makes a url safe string in to a capitalized string [OPTIONAL]

The download is now over at its designated page at masugadesign.com: http://www.masugadesign.com/the-lab/scripts/urlsafe/

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
18 years ago
Ingmar Greil's avatar Ingmar Greil

When you say “URL-safe”, how does it handle characters which must not appear in a URL? Like, umlauts, ampersands, etc?

       
Daniel Walton's avatar
Daniel Walton
553 posts
18 years ago
Daniel Walton's avatar Daniel Walton

Looking at the code i’d say it has no support for removing/replacing those characters. For true URLsafe’ness why not just urlencode the string? Dirty? that’s a matter of opinion, Safe? yes

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
18 years ago
Ingmar Greil's avatar Ingmar Greil

Yes, urlencoding would be the way to go, I think.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
18 years ago
Ryan M.'s avatar Ryan M.

This was put together really quickly for a project that, apparently, didn’t have any wacky characters going on in the Category titles. I think this plugin may be misnamed. All this was supposed to do was take already approved category names and make those quote-enquote “urlsafe”. If you can’t put an umlaut in an EE category name (can you? haven’t tried…), then this didn’t have to bother with it.

So, I think in the interest of this being usable for more than making category names into “url titles” more-or-less (like I said, I think this whole thing might be obsolete now…) it might need an update. I posted this because I thought it was something that might help davenport use category names in the URL as opposed to Cx.

Did this post even make sense? I’m so hungry I can’t think straight.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
18 years ago
Ingmar Greil's avatar Ingmar Greil
This was put together really quickly for a project that, apparently, didn’t have any wacky characters going on in the Category titles. I think this plugin may be misnamed.

Well, slightly misleading, perhaps … But I am sure we can have it live up to its name in no time.

If you can’t put an umlaut in an EE category name (can you? haven’t tried…), then this didn’t have to bother with it.

But you can, most definitely.

I’m so hungry I can’t think straight.

Me, too, actually. Off to get something between my teeth.

       
Nathan Pitman's avatar
Nathan Pitman
531 posts
17 years ago
Nathan Pitman's avatar Nathan Pitman

I wrote a little plug-in yesterday to encode/decode using url or base64…

http://nathanpitman.com/journal/547/expressionengine-plug-in-encodedecode

😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.