Evilripper Blog

A programmer's work is never done

  • Home
  • Downloads
  • News
  • Sfondi Desktop
  • About Me

30

ott

Urlencode Javascript – Urldecode Php

Posted by evilripper  Published in development, javascript

Siccome dovevo passare un testo tramite GET con ajax mi ero ritrovato con un piccolo problema di caratteri! :-( per esempio se c’era un & commerciale mi si troncava etc…

Visto che escape() di javascript non e’ full compatibile con la funzione di decodifica di php, ho trovato questo script per fare un urlencode in javascript cosi’ riesco a decodificarlo lato server tramite la funzione urldecode() di php:

  1.  
  2. // ====================================================================
  3.  
  4. //       URLEncode and URLDecode functions
  5.  
  6. //
  7.  
  8. // Copyright Albion Research Ltd. 2002
  9.  
  10. // http://www.albionresearch.com/
  11.  
  12. //
  13.  
  14. // You may copy these functions providing that
  15.  
  16. // (a) you leave this copyright notice intact, and
  17.  
  18. // (b) if you use these functions on a publicly accessible
  19.  
  20. //     web site you include a credit somewhere on the web site
  21.  
  22. //     with a link back to http://www.albionresearch.com/
  23.  
  24. //
  25.  
  26. // If you find or fix any bugs, please let us know at albionresearch.com
  27.  
  28. //
  29.  
  30. // SpecialThanks to Neelesh Thakur for being the first to
  31.  
  32. // report a bug in URLDecode() – now fixed 2003-02-19.
  33.  
  34. // And thanks to everyone else who has provided comments and suggestions.
  35.  
  36. // ====================================================================
  37.  
  38. function URLEncode(str)
  39.  
  40. {
  41.  
  42.  // The Javascript escape and unescape functions do not correspond
  43.  
  44.  // with what browsers actually do…
  45.  
  46.  var SAFECHARS = "0123456789" +                                 // Numeric
  47.  
  48.                                 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +  // Alphabetic
  49.  
  50.                                 "abcdefghijklmnopqrstuvwxyz" +
  51.  
  52.                                 "-_.!~*’()";                                    // RFC2396 Mark characters
  53.  
  54.  var HEX = "0123456789ABCDEF";  var plaintext = str;
  55.  
  56.  var encoded = "";
  57.  
  58.  for (var i = 0; i < plaintext.length; i++ ) {
  59.  
  60.         var ch = plaintext.charAt(i);
  61.  
  62.      if (ch == " ") {
  63.  
  64.             encoded += "+";                             // x-www-urlencoded, rather than %20
  65.  
  66.         } else if (SAFECHARS.indexOf(ch) != -1) {
  67.  
  68.             encoded += ch;
  69.  
  70.         } else {
  71.  
  72.             var charCode = ch.charCodeAt(0);
  73.  
  74.                 if (charCode > 255) {
  75.  
  76.                     alert( "Unicode Character ‘"
  77.  
  78.                         + ch
  79.  
  80.                         + "’ cannot be encoded using standard URL encoding.\n" +
  81.  
  82.                                   "(URL encoding only supports 8-bit characters.)\n" +
  83.  
  84.                                           "A space (+) will be substituted." );
  85.  
  86.                         encoded += "+";
  87.  
  88.                 } else {
  89.  
  90.                         encoded += "%";
  91.  
  92.                         encoded += HEX.charAt((charCode >> 4) &amp; 0xF);
  93.  
  94.                         encoded += HEX.charAt(charCode &amp; 0xF);
  95.  
  96.                 }
  97.  
  98.         }
  99.  
  100.  } // for
  101.  
  102. //document.URLForm.F2.value = encoded;
  103.  
  104.  return encoded;
  105.  
  106.  //return false;
  107.  
  108. };

Link & Fonti

Il codice l’ho preso da http://www.albionresearch.com/misc/urlencode.php ed e’ stato adattato in una funzione a cui si passa il valore da codificare e restituisce il testo codificato.

no comment

Multilanguages

  • English
  • Italiano
Confronta i prezzi per Portatili!  Recensioni per Palmari
Le migliori recensioni: iPad PC Portatili Stampanti
Ricerca Prodotti:

Comparazione prezzi su Ciao
Ciao Box Generator

Affiliates & Sponsor

Add to Technorati Favorites

Paperblog

Il Bloggatore
Aggregatore di blog

Smilla Magazine


BlogItalia.it - La directory italiana dei blog

Tophost Hosting

8.890 commenti spam
bloccato da
Akismet

Locations of visitors to this page

My Flikr

Rock TotemRock TotemFiorenzuola di focaraSiroloSirolothe real oil priceEarly daysImprisonedTranquilitydawn

Social Connection







Blogroll

  • 2008computer
  • AumentaTrafficoWeb
  • Rocco Blog
  • jumping head shot
  • Libertà di scatto
  • Il blog di Paolo Ratto
  • il blog del picchio!
  • Skass Computer
  • The Developers
  • gyf.it
  • lu01 rock band
  • www.lugido.com
  • Michele Focchi
  • Michele Papaleo
  • Lo scannatoio
  • xoen->blog();

Categories

  • database (1)
  • development (17)
    • CSharp (4)
    • delphi (3)
    • javascript (1)
    • php (5)
    • vb.net (1)
  • facebook (1)
  • fotografia (1)
  • hacking (5)
  • hardware (19)
    • mobile (2)
  • internet (60)
    • cms (1)
    • google (12)
    • seo (1)
    • wordpress (4)
  • linux (6)
    • gentoo (4)
  • microsoft (5)
  • Senza categoria (5)
  • software (15)
  • videogames (7)
    • unreal tournament 3 (1)
  • winXp (2)

Archives

  • agosto 2010 (2)
  • luglio 2010 (2)
  • giugno 2010 (3)
  • maggio 2010 (14)
  • aprile 2010 (9)
  • marzo 2010 (6)
  • febbraio 2010 (6)
  • gennaio 2010 (6)
  • dicembre 2009 (4)
  • novembre 2009 (1)
  • ottobre 2009 (5)
  • settembre 2009 (3)
  • luglio 2009 (2)
  • maggio 2009 (1)
  • aprile 2009 (1)
  • marzo 2009 (2)
  • febbraio 2009 (1)
  • gennaio 2009 (2)
  • dicembre 2008 (3)
  • novembre 2008 (4)
  • settembre 2008 (3)
  • giugno 2008 (3)
  • maggio 2008 (1)
  • aprile 2008 (1)
  • marzo 2008 (1)
  • febbraio 2008 (4)
  • gennaio 2008 (4)
  • dicembre 2007 (2)
  • novembre 2007 (4)
  • ottobre 2007 (7)
  • settembre 2007 (5)
  • agosto 2007 (2)
  • luglio 2007 (1)
  • giugno 2007 (2)

Recent Entries

  • Comprare la prima reflex digitale
  • Skass computer un blog sulla tecnologia
  • Mini pc silenziosi ed economici
  • Spreaker e il dj sei tu! [Intervista]
  • Mondiali fifa 2010 risultati in tempo reale su Firefox
  • WinSxS l’inferno delle dll
  • Internet ha gli IP contati
  • Promozione hosting a 5,99 euro su tophost.it
  • Commenti NoFollow free
  • I posti più visitati del mondo

Recent Comments

  • Random Selection of Posts

    • Assistenza online personalizzata
    • Vota la t-shirt ufficiale di Mozilla 2010
    • Il Bloggatore Feed Aggregator
    • La lenta morte di Internet Explorer
    • Panasonic TZ5 Recensione
    • 25 anni fa inizio’ tutto da una C=64
    • Download Windows7 Gratis?
    • Quanto guadagnano le facebook apps?
    • Chi vuole un xbox a 99 euro?
    • Come inserire il bottone di Facebook Mi Piace nel blog
© 2008 Evilripper Blog is proudly powered by WordPress
Theme designed by Roam2Rome