Forum Moderators: coopster
We have a process that does something like this:
1. take data from user
2. put data into xml
3. post xml to receiving script
4. use simplexml to read incoming xml
5. make a new xml string for receiving script 2
5. post the reformatted xml to receiving script 2
complications include html special characters, url encoding and charsets.
I've gotten to step 4 -- I receive an iso-8859-1 encoded xml string on POST. When I do simplexml_load_string, the spanish characters turn into useless garbage.
for example:
$xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
$xml .= "<data>spanish cháractérs</data>";
$incomingXML = simplexml_load_string( $xml );
echo $incomingXML->data;
output will be: spanish cháractérs
I'm using iso-8859-1 because apparently utf-8 doesn't understand spanish characters. every time I try a utf8_encode, or an htmlentities with utf-8 as the encoding, the script breaks completely.
has anyone had to tackle a similar problem?
1. urlencode - it *seems* to turn spanish characters to gibberish
2. simplexml_load_string - it *seems* to break when I send spanish characters
for example, for # 1, I have the following test page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<p>just checking: èá</p>
<?
$string = "& spanish cháractér's";
$encodedString = urlencode( $string );
$deEncodedString = urldecode( $encodedString );
echo "<p>" . $string . "</p>\r\n";
echo "<p>" . $encodedString . "</p>\r\n";
echo "<p>" . $deEncodedString . "</p>\r\n";
?>
</body></html>
The output for the above on my server is:
just checking: èá
& spanish cháractér's
%26+spanish+ch%C3%A1ract%C3%A9r%27s
& spanish cháractér's
Notice how line 3 appears to be just gibberish (check it online here - if you deencode the string, it's garbage): [meyerweb.com...]
But the php urldecode turns it right back to normal. So I don't know what the situation is there