alienhelpdesk.com
projects
Project London
The latest movie directed by Ian Hubert! And I get to help!
usefull sites
blenderartists.org
Home of the blender artist community

javascript make safe url

This is a function that makes a string url safe.
Nice for creating friendly urls that are actually friendly.

  1. // Function for making sure text only uses url safe symbols
  2. function makeSafe(thisText, allowSpace){
  3.         var w = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
  4.         var s = 'abcdefghijklmnopqrstuvwxyz0123456789-_';
  5.         var x = new Array('àáâãäå', 'ç', 'èéêë', 'ìíîï', 'ñ', 'ðóòôõöø', 'ùúûü', 'ýÿ');
  6.         var r = new Array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y');
  7.  
  8.         if(allowSpace){
  9.                 s = s + ' ';
  10.         }
  11.  
  12.         thisText = thisText.toLowerCase();
  13.         var newText = new Array();
  14.  
  15.         for (i = 0; i < thisText.length; i++){
  16.                 thisChar = thisText.charAt(i);
  17.                 if(w.indexOf(thisChar) == -1){
  18.                         if(s.match(''+thisChar+'')){
  19.                                 newText[i] = thisChar;
  20.                         }else{
  21.                                 for (j = 0; j < x.length; j++){
  22.                                         if(x[j].match(thisChar)){
  23.                                                 newText[i] = r[j];
  24.                                         }
  25.                                 }
  26.                         }
  27.                 }
  28.         }
  29.  
  30.         return newText.join('');
  31. }
Display clean javascript code for copying
// Function for making sure text only uses url safe symbols
function makeSafe(thisText, allowSpace){
	var w = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
	var s = 'abcdefghijklmnopqrstuvwxyz0123456789-_';
	var x = new Array('àáâãäå', 'ç', 'èéêë', 'ìíîï', 'ñ', 'ðóòôõöø', 'ùúûü', 'ýÿ');
	var r = new Array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y');

	if(allowSpace){
		s = s + ' ';
	}

	thisText = thisText.toLowerCase();
	var newText = new Array();

	for (i = 0; i < thisText.length; i++){
		thisChar = thisText.charAt(i);
		if(w.indexOf(thisChar) == -1){
			if(s.match(''+thisChar+'')){
				newText[i] = thisChar;
			}else{
				for (j = 0; j < x.length; j++){
					if(x[j].match(thisChar)){
						newText[i] = r[j];
					}
				}
			}
		}
	}

	return newText.join('');
}
Japanese proverb
Atama kakushite, shiri kakusazu
Cover your head, and not cover your bottom
Introducing character animation with Blender
Introducing character animation with Blender
The classic by Tony Mullen
Essential Blender
Essential Blender
The official guide!