ROBERT WHEELER

Web Designer / Web Developer / Digital Marketer


Add the latest FCO updates to your travel website with PHP

If you run a travel based website in the UK, the FCO publishes an atom feed (The Atom Syndication Format is an XML language used for web feeds) numerous times a day with the latest updates for UK holidaymakers traveling to foreign countries.

Using the snippet of PHP code below you can easily add a page (fco.php) to your travel website that instantly updates with the latest FCO updates on a page load.

The PHP Code


<?php

$atom = simplexml_load_file('https://www.gov.uk/foreign-travel-advice.atom');

echo '<h1><a href="'. $atom->link[href] .'">' . $atom->title . '</a></h1>';

$dmy = date('g:ia jS F Y', strtotime('+1 hour', strtotime($atom->updated)));
echo '<p>Updated: <b>' . $dmy . '</b></p><br>';

foreach ($atom->entry as $item) {
  echo '<h2><a href="'. $item->link[href] .'">FCO Travel Advice ' . $item->title . '</a></h2>;
  echo '<p>' . str_replace(array("Latest update: ", ""), "", $item->summary->div->p) . '</p>';
  $dmy2 = date('g:ia jS F Y', strtotime('+1 hour', strtotime($item->updated)));
  echo '<small>' . $dmy2 . '</small>';
 }

?>