Posted By

szsk on 08/10/06


Tagged

escape html String encode


Versions (?)

encode numeric character reference


 / Published in: JavaScript
 

  1. String.prototype.ncr2c = function( ) {
  2. return this
  3. .replace( /&#x([\da-f]{2,4});/gi,
  4. function( $0, $1 ) { return String.fromCharCode( "0x" + $1 ) } )
  5. }
  6. String.prototype.c2ncr = function( ) {
  7. return this .ncr2c( ).replace( /./g,
  8. function( $0 ) { return "&#x" + $0.charCodeAt( ).toString( 16 ).toUpperCase( ) + ";" } )
  9. }
  10.  
  11. alert( "ajax".ncr2c( ) );
  12. //ajax
  13.  
  14. alert( "ajax".c2ncr( ) );
  15. //ajax

Report this snippet  

You need to login to post a comment.