Posted By

psema4 on 08/31/10


Tagged


Versions (?)

URI encoding with perl and javacsript


 / Published in: Perl
 

  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use CGI;
  7. use URI::Escape;
  8.  
  9. my $q = new CGI;
  10. my $buf = $q->param('buf') || "This is an ampersand... &\n";
  11. my $safe = uri_escape($buf);
  12. my $verysafe = uri_escape("foo", "\0-\377");
  13. my $str = uri_unescape($safe);
  14.  
  15. print qq[content-type: text/html\n\n
  16. <html>
  17. <head>
  18. <title>URI Encoding</title>
  19. <script type="text/javascript">
  20. function preencode() {
  21. var buf = document.getElementById('buf').value;
  22. document.getElementById('preencode').value = escape(buf);
  23. }
  24. </script>
  25. </head>
  26.  
  27. <body>
  28. <form method="GET">
  29. <input type="text" value="$buf" id="buf" name="buf" />
  30. <input type="submit" />
  31. </form>
  32. <div>
  33. <input type="text" value="" id="preencode" name="preencode" />
  34. <button onclick="preencode()">Pre-encode</button>
  35. </div>
  36. <div>
  37. <h4>Safe</h4>
  38. <p>$safe</p>
  39. <h4>Very Safe</h4>
  40. <p>$verysafe</p>
  41. <h4>Str</h4>
  42. <p>$str</p>
  43. </div>
  44. </body>
  45. </html>
  46. ];

Report this snippet  

You need to login to post a comment.