Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Character Replacement Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var str='Ñ ñ á é í ó ú & £ €';
function rep(t){
var t=t;
for (var i = 0; i < rep.ar.length; i++)
t=t.replace(rep.ar[i++], rep.ar[i]);
return t;
}
rep.ar=[
//unicode | entity/string
/\u0026/g, '&', //the ampersand (&) must be first or else it will be replaced in other replacements
/\u00d1/g, 'Ñ',
/\u00f1/g, 'ñ',
/\u00e1/g, 'á',
/\u00e9/g, 'é',
/\u00ed/g, 'í',
/\u00f3/g, 'ó',
/\u00fa/g, 'ú',
/\u00a3/g, 'sterling',
/\u20ac/g, 'euros' //note - no comma after last entry
];
</script>
</head>
<body>
<form name="repform" action="#">
<input name="vals" type="hidden"><br>
<input type="submit" value="Go!">
</form>
<script type="text/javascript">
document.forms['repform']['vals'].value=rep(str);
</script>
<input type="button" value="Alert" onclick="alert(rep(str));">
</body>
</html>
Bookmarks