Somewhere its getting twisted. All the text is retrieved and displayed
correctly except the Swedish characters used in some of the words that
are stored in my mysql phpmyadmin database.
These are displayed seriously incorrectly. Each character deletes the
following 2 characters. Så "påskvecka" becmes p*vecka where * is an
upright diamond with a question mark in it. This offending character
can not be copied into this newsgroup posting, it just wont take it.
Everything else on the page is correctly (Swedish characters written
elsewhere ARE displayed correctly, the problem ONLY applies to the
ones retrieved with php code via ajax from the server.
So what is the php code to turn the correctly stored characters in the
mysql phpmyadmin database back into the correct ones before displaying
junk.
Not quite understandning that....
This is the code from my php file....
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
else
{
alert("Använd knapparna längst ner på sidan");
}
}
function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = "loaded"
if (xmlhttp.status==200)
{// 200 = "OK"
document.getElementById('T1').innerHTML=xmlhttp.responseText;
}
else
{
alert("Problem med datahämtning:" + xmlhttp.statusText);
}
}
}
Where do I paste in your answer to that code?
Garry Jones
Sweden
Ah, what you are looking for is someone to do the job for you? :S
Just override the mime-type before sending the query to the server.
The first thing you need to understand is the difference between PHP and
Javascript. PHP runs on the server; the javascript code you posted runs
on the client.
Try comp.lang.javascript for your javascript questions.
If you have PHP code to discuss, this is the correct place. But you
haven't shown us anything indicating whether or not this is a PHP
problem yet.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================
I changed THIS
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
TO THIS
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("POST",url,true);
void overrideMimeType(
in AUTF8String ('text/xml; charset=iso-8859-1');
xmlhttp.send(null);
}
But no luck, I don't actually understand much of this syntax. I
realise also I may be in the wrong newsgroup, not all files that end
in .php are php problems but I thought there might be so php code to
sort this problem out.
I'd be enternally greatful if someone could push me (hard) in the
right direction...
Garry Jones
Sweden
You should do it this way.-
xmlhttp.overrideMimeType('text/html; charset=UTF-8');
(assuming you are retrieving html data in UTF-8)
> I'd be enternally greatful if someone could push me (hard) in the
> right direction...
Well, lets hope this works.
I tried this..
xmlhttp.onreadystatechange=state_Change;
xmlhttp.overrideMimeType('text/html; charset=UTF-8');
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
Still does not work.
However the people in javascript showed me how to do this with php.
I convert the data retrieved from the server with ICONV to UTF-8.
For instance:
$resmalid=iconv("ISO-8859-1", "UTF-8", $b4resmalid);
This works with server and user entered data but for the raw display
data with Swedish characters I have on the pages I construck I have to
use the codes, so its only a work around but it solves the problem. So
a php solution works for the main problem....
Please post an URL where I can see the output from the PHP file.
Post in an appropriate newsgroup and you'll get good answers. Continue
to post in the wrong newsgroup and you'll continue to get crap answers,
like you have so far.
It would be much better if he posted this to an appropriate newsgroup
such as comp.lang.javascript - where he will get GOOD advice.
This is a PHP newsgroup (hint: that's why the "php" in it's name), not a
javascript newsgroup. Please learn the difference.
Internally, computers can only handle numbers. So when you need to use
text you must use a translation table to convert each individual letter
into a number. Such table is called "character set" (or charset) and
there're many to choose from. The first step is to pick a charset that's
suitable for Swedish words and make sure all your applications (MySQL,
PHP, JavaScript, HTML...) are using it properly.
I've found this article very illustrative:
http://www.joelonsoftware.com/articles/Unicode.html
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
header( 'Content-type: text/html; Charset: utf-8');
(im typing this from the top of my head so syntax is probably wrong :) )
Brko