Hello I just start to develop php what I want to do is to get xml contents from another site but when i get it like this
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_ENCODING => "UTF-8", // handle compressed
CURLOPT_USERAGENT => "spider", // who am i
);
$ch = curl_init("http://wxxx.xml");
curl_setopt_array( $ch, $options );
$file = curl_exec( $ch );
curl_close( $ch );
it returns corrupted characters I can make it look like ok when I change header of page to UTF-8 but the problem is that I cannot insert these variables to database they are corrupted there too, How can I fix this? thank you for any answer.
If the characters are fine when you change the header of the page to indicate that it’s encoded in UTF-8, they’re not corrupted; you’re treating character data that’s encoded in one format (UTF-8) as though it were encoded in another.
What you should check:
Verify that the XML source document is, in fact, UTF-8 encoded, since that’s what you’re specifying in your curl options.
Find out what the encoding used by your database is.
If you need to be able to store Unicode characters in your database, you can change the character encoding there to UTF-8. Alternatively, you can convert from your source document using
utf8_decode()(if the database is storing ISO-8859-1 characters) ormb_convert_encoding(). However, if characters in the source document can’t be encoded in the system being used by the database, you’ll lose information.