Question : Replacing specific characters with character entities such as ä etc.

Hi guys

I want to try a thing out and when doing an Ajax GET-call to a page replace every instance
of a specific character, in my case, nordic characters like: å, Å, ä, Ä, ö, Ö
with the character entities å Å ä Ä ö Ö

I want to do this since i want a quick solution wich can alter a pages information without saving it to the server since not every web hotel allows you to alter local server files at runtime. If i don't replace them at all my page will display questionmarks instead.

I have even tried to add this meta-code:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />  

to the php-file that i call thru Ajax, It doesn't alter a thing, even if i add html, head and body.

The main page where the DIV-element content_center is located at has this meta-code
on it, and there the åäöÅÄÖ is translated to the correct character entities.

If i could change the åäöÅÄÖ on the page without having to replace the characters with a separate function i would be very happy.. otherwise hit me with some nice ideas.

This is the code wich calls the php-page.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {	
			document.getElementById("content_center").innerHTML=xmlhttp.responseText;
		}
	}
	
	xmlhttp.open("GET","page.php",true);
	xmlhttp.send();	



The page i'm getting outputs pure php-code wich is then captured by Ajax-function and outputted to the DIV-element "content_center".


Answer : Replacing specific characters with character entities such as &auml; etc.

your server send you utf-8 characters so it's ok.
set utf-8 in the header of your page : < meta http-equiv="Content-Type" content="text/html; charset=utf-8" / >
Random Solutions  
 
programming4us programming4us