Alıntı:
perplex tarafından gönderilen mesaj:
XML i nasıl yazdırıyorsun?
|
XML'i yazdıran fonksiyon anladığım kadarıyla şu:
Kod:
function createExhibitionXML($lang='tr',$type) {
$header = "<?XML version=\"1.0\" encoding=\"UTF-8\"?>\n";
if ($lang == 'eng') {
$baslik = "mpProTitleeng";
$metin = "mpProTexteng";
$AltText = "mpProAltTexteng";
$aciklama = "descriptioneng";
} else {
$baslik = "mpProTitle";
$metin = "mpProText";
$AltText = "mpProAltText";
$aciklama = "description";
}
$projectArray = getAktivProjects($type);
for($i=0;$i<count($projectArray);$i++) {
$photo_array = getPhotosByID($projectArray[$i]['mpProID']);
$list .="<menu>\n";
$list .="<menuname>";
$list .=$projectArray[$i][$baslik];
$list .="</menuname>\n";
$list .="<date>";
$list .=$projectArray[$i]['gunc_tar'];
$list .="</date>\n";
$list .="<explain>";
$list .=$projectArray[$i][$metin];
$list .="</explain>\n";
$list .="<gallery>\n";
if (count($photo_array) > 0) {
for($p=0;$p<count($photo_array);$p++) {
$pp .="<pic>\n";
$pp .="<filename>";
$pp .=$photo_array[$p]['filename'];
$pp .="</filename>\n";
$pp .="<explain>";
$pp .=$photo_array[$p][$aciklama];
$pp .="</explain>\n";
$pp .="</pic>\n";
}
$list .=$pp;
}
$list .="</gallery>\n";
$list .="<content>";
$list .=$projectArray[$i][$AltText];
$list .="</content>\n";
$list .="</menu>\n";
}
$full_xml = "<data>\n".$list."</data>";
if ($type == 2) {
$filename = "/home/httpd/vhosts/mp.com/httpdocs/".$lang."/exhibition.XML";
//$filename = "../".$lang."/exhibition.XML";
} else {
$filename = "/home/httpd/vhosts/mp.com/httpdocs/".$lang."/projects.XML";
//$filename = "../".$lang."/projects.XML";
}
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
sendajaxheaders();
if (!$fp = fopen($filename, 'w')) {
//print "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($fp, $somecontent)) {
//print "Cannot write to file ($filename)";
exit;
}
//print "Success, wrote ($somecontent) to file ($filename)";
fclose($fp);
} else {
//print "The file $filename is not writable";
}
}
Bu fonksiyonun içinde kullanılan iki tane fonksiyon daha var onlar da şunlar:
Kod:
function getAktivProjects($type) {
$sqltext = "select * from mp_projects where mpProType = ".$type." AND mpProStatus = 'A' order by mpProDate ASC";
$sonuc = mysql_query($sqltext);
if($sonuc) {
for($k=0;$k<mysql_num_rows($sonuc);$k++) {
$myArray[$k] = mysql_fetch_array($sonuc);
}
}
return $myArray;
}
function getPhotosByID($proID) {
$sqltext = "select * from mp_lists where proID = ".$proID." order by image_order ASC";
$sonuc = mysql_query($sqltext);
if($sonuc) {
for($k=0;$k<mysql_num_rows($sonuc);$k++) {
$myArray[$k] = mysql_fetch_array($sonuc);
}
}
return $myArray;
}