Posts Tagged ‘technology’

Javascript get a nice uri from string

This function will transform a string into a nice uri.

You can use this to get a good level seo uri for all your links

function getNiceURI(_dirtyUri)
_dirtyUri = _dirtyUri.toLowerCase();
if(_dirtyUri === "") return _dirtyUri;

var encodedURI = encodeURIComponent(_dirtyUri);
var niceURI = encodedURI.replace(/[%20]/g,”_”);
niceURI = niceURI.replace(/[^a-zA-Z0-9-_]/g, ‘_’);

//Elimino eventuali underscore dal primo carattere
while(niceURI.indexOf(“_”) === 0) {
niceURI = _dirtyUri.substring(1, niceURI.length);

//Deleting underscores from beginning and end string
while(niceURI.lastIndexOf(“_”) === niceURI.length – 1) {
niceURI = niceURI.substring(0, niceURI.length – 1);

//Take off repeated underscores
while(niceURI.indexOf(“__”) !== -1) {
niceURI = niceURI.replace(“__”, “_”);

return niceURI;



8 September 2012 Leave a comment

Hello word! Hi unify a lot of functions used every day by me and others developers
in a static class ready to use into your projects.

Why a static class?
Simply ’cause with it if you already have a function with the same name your script
will not crash 🙂

Download it here

You can find complete documentation here:

Please post your comments and request on the main site

and not here.

Thanks to all contributors

%d bloggers like this: