query($query); if (PEAR::isError($stmt)) { die($stmt->getMessage()); } $result = $stmt->fetchAll(); /* echo '
';
print_r($result);
echo '
'; */ //global variables $replacements = array("'" => ''', "£" => "£","€" => "€","á" =>"a","í" => "i","è" => "e","é" => "e","ü" => "u","ù"=> "u","ç" => "c","ñ" => "n", "ó" => "o", "¿" => "?","Á" => "A","É" => "E", "Í" => "I", "Ó" => "O","Ö" =>"O", "Ú" => "U", "Ñ" => "N", "Ü" => "U", "½" => ".5" ); // create doctype $dom = new DOMDocument("1.0","UTF-8"); $dom->formatOutput = true; // display document in browser as plain text // for readability purposes //header("Content-Type: text/plain"); header("Content-type: text/xml"); // create root element $root = $dom->createElement("feed"); $dom->appendChild($root); $headerdescriptionadd = true; // display document in browser as plain text // for readability purposes foreach($result as $key => $row) { $storyId = $row['story_id']; $headline = utf8_encode($row['headline']); $smsLine = utf8_encode($row['abstract']); $detail = utf8_encode($row['detail']); $teamId = $row['team_id']; $storyType = $row['story_type']; $teamName = $row['teamname']; $fixtureId = $row['match_id']; $tstamp = $row['tstamp']; $imageId = $row['image_id']; /** Some processing on pics....***/ $filepath = ""; if ($imageId > 0) { $imagepath = $row['location']; //note the DB image path will be like C:\Feeds\Images\Match Reports\rs_20140211221445.jpg //need to convert to http://feeds.ics-sport.com/images/Match Reports/rs_20140211221445.jpg $filepath=str_replace('C:\\Feeds\\Images\\','http://feeds.ics-sport.com/images/',$imagepath); $filepath=str_replace('\\','/',$filepath); //$fullImageURL = $filepath; } $newsfeed = $dom->createElement("newsfeed"); $root ->appendChild($newsfeed); //feedinfo $feedinfo = $dom->createElement("feedinfo"); $newsfeed->appendChild($feedinfo); $supplier = $dom->createElement("suplier"); $feedinfo->appendChild($supplier); $suppliervalue = $dom->createTextNode("Rivals Publishing"); $supplier->appendChild($suppliervalue); $categorycode = $dom->createElement("categorycode"); $feedinfo->appendChild($categorycode); $categorycodevalue = $dom->createTextNode("0"); $categorycode->appendChild($categorycodevalue); $categoryname = $dom->createElement("categoryname"); $feedinfo->appendChild($categoryname); $categorynamevalue = $dom->createTextNode($teamName); $categoryname->appendChild($categorynamevalue); $categoryid = $dom->createElement("categoryid"); $feedinfo->appendChild($categoryid); $categoryidvalue = $dom->createTextNode($teamId); $categoryid->appendChild($categoryidvalue); $subscriptionid = $dom->createElement("subscriptionid"); $feedinfo->appendChild($subscriptionid); $subscriptionidvalue = $dom->createTextNode("0"); $subscriptionid->appendChild($subscriptionidvalue); $requestid = $dom->createElement("requestid"); $feedinfo->appendChild($requestid); $requestidvalue = $dom->createTextNode("0"); $requestid->appendChild($requestidvalue); $language = $dom->createElement("language"); $feedinfo->appendChild($language); $languagevalue = $dom->createTextNode("en-us"); $language->appendChild($languagevalue); //feedcontent $feedcontent = $dom->createElement("feedcontent"); $newsfeed->appendChild($feedcontent); $article = $dom->createElement("article"); $article->setAttribute('id',$storyId); $feedcontent->appendChild($article); $metadata = $dom->createElement("metadata"); $article->appendChild($metadata); $author = $dom->createElement("author"); $authorvalue = $dom->createTextNode("Rivals Publishing"); $author->appendChild($authorvalue); $metadata->appendChild($author); $copyright = $dom->createElement("copyright"); $copyrightvalue = $dom->createTextNode("Rivals Publishing"); $copyright->appendChild($copyrightvalue); $metadata->appendChild($copyright); $vendor = $dom->createElement("vendor"); $vendorvalue = $dom->createTextNode("Rivals Publishing"); $vendor->appendChild($vendorvalue); $metadata->appendChild($vendor); //header $header = $dom->createElement("header"); $article->appendChild($header); $headerid = $dom->createElement("id"); $headeridvalue = $dom->createTextNode($storyId); $headerid->appendChild($headeridvalue); $header->appendChild($headerid); $headertitle = $dom->createElement("title"); $headertitlevalue = $dom->createTextNode($headline); $headertitle->appendChild($headertitlevalue); $header->appendChild($headertitle); $headerfixtureid = $dom->createElement("fixture_id"); $headerfixturevalue = $dom->createTextNode($fixtureId); $headerfixtureid->appendChild($headerfixturevalue); $header->appendChild($headerfixtureid); $headermodified = $dom->createElement("modified_date"); $headermodifiedvalue = $dom->createTextNode($tstamp); $headermodified->appendChild($headermodifiedvalue); $header->appendChild($headermodified); //ful version $full = $dom->createElement("fullversion"); $article->appendChild($full); $fullheadline = $dom->createElement("headline"); $fullheadlinevalue = $dom->createTextNode($headline); $fullheadline->appendChild($fullheadlinevalue); $full->appendChild($fullheadline); $fullstrapline = $dom->createElement("strapline"); $fullstraplinevalue = $dom->createTextNode($smsLine); $fullstrapline->appendChild($fullstraplinevalue); $full->appendChild($fullstrapline); $fullimage = $dom->createElement("image"); $fullimage->setAttribute('id',$imageId); $fullimage->setAttribute('url',$filepath); $imagecaption = $dom->createElement("imagecaption"); $fullimage->appendChild($imagecaption); $full->appendChild($fullimage); $fullbodytext = $dom->createElement("bodytext"); $fullbodytextvalue = $dom->createTextNode($detail); $fullbodytext->appendChild($fullbodytextvalue); $full->appendChild($fullbodytext); } // save and display tree echo $dom->saveXML(); } else { echo 'You do not have access to this feed from the following IP address: ' . $users_IP_address . ''; echo '
'; echo 'Please contact your provider...'; } ?>