sitemap.xml土耳其字符

that's my php code;

//Encode ANSI
function donustur($str){
    $eski = array('Ç', 'Ş', 'Ğ', 'Ü', 'İ', 'Ö', 'ç', 'ş', 'ğ', 'ü', 'ö', 'ı', ' ','&');
    $yeni = array('c', 's', 'g', 'u', 'i', 'o', 'c', 's', 'g', 'u', 'o', 'i', '-','&');
    return str_replace($eski,$yeni,$str);
}

header('Content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"ISO8859-9\" ?>
";
echo "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">";

echo "<url>
  <loc>http://www.sitem.com/</loc>
  <changefreq>daily</changefreq>
</url>";

$d = "\t<changefreq>daily</changefreq>
";

$kategoriCek = mysql_query("SELECT * FROM kategoriler");
while($kat = mysql_fetch_array($kategoriCek)){
   echo "<url>
";
   echo "\t<loc>http://www.sitem.com/".$kat['id']."-".donustur(strtolower($kat['kategoriadi']))."-kategori.html</loc>
";
   echo $d;
   echo "</url>
";
}

echo "</urlset>
";

output;

<loc>http://www.sitem.com/93-??-guvenl?k-kategori.html</loc>

I want should be like that;

<loc>http://www.sitem.com/93-is-guvenlik-kategori.html</loc>

UTF-8 and UTF-8 not BOM or encoding="ISO8859-9", encoding="UTF-8" doesn't work it.

How we do solve?

Thank you for your interest. Good works..

Sitemaps following the Sitemap protocol format must be UTF-8 encoded:

The Sitemap protocol format consists of XML tags. All data values in a Sitemap must be entity-escaped. The file itself must be UTF-8 encoded.

So for example what you do at the very beginning:

 <?xml version=\"1.0\" encoding=\"ISO8859-9\" ?>

Is already wrong because that encoding is not supported by XML sitemaps. As you also wrote in your question that you just interchanged the string there (e.g. to "UTF-8") but you lost no word at all about the encoding of the actual output, you most likely just output bad encoded character data and perhaps even XML.

There are two things you can do to greatly improve this and reduce the chance of such errors:

  1. Find out in which encoding the characters you have for input are. Convert those into UTF-8 before passing them into the output processing.
  2. Use a library like SimpleXML or XMLWriter to generate the XML. You do not need to do that all your own. These libraries already take care of the encoding.