Hi Guys,

I'm wishing to write a PHP script that parses an RSS feed on a local travel agent website, and emails me whenever there are deals to/from particular destinations. Downloading the RSS file seems easy enough, looks like I can use Preg_Grep to find the destinations I'm after and assign the values to an array. The bit I'm stuck with is how I write an IF statement that says, if any of the values within the array equal <destination> echo "There are flights to <destination>". I'll get it to email me the results but an echo will be fine for now.

Secondly, is there anyway to get a server to execute a PHP script server side? or should I be writing this in BASH to begin with? I don't particularly want to have to visit my PHP file each day for the check to be performed. a crontab or something would be ideal.

Any help appreciated,

Thanks

    Thanks Clooth, I've used crontab heaps but didn't realise you could execute a PHP file using the executable itself, assumed it had to be through apache or something!

    So far my code is:

    <?php
    $file = 'http://domain.com/rss.xml';
    $data = file($file) or die('Could not read file!');
    $exploded = explode(" ",$data);
    if (in_array("London", $exploded)) {
    echo "Trips to London";}
    else {
    echo "no trips to london";}
    ?>

    It's reading the file OK but I dont think I have the manipulation right just yet. I wish I had sed for linux, in PHP 🙂

      A simple solution you might try as a starting point:

      $file = 'http://domain.com/rss.xml';
      $data = file($file) or die('Could not read file!');
      $matches = preg_grep('/London/i', $data);
      if(count($matches))
      {
        // found trips to London, loop through array $matches for details
      }
      else
      {
        // no matches found for London
      }
      
        Write a Reply...