You are here:  » TV Guide


TV Guide

Submitted by russellharrower on Tue, 2009-04-28 11:46 in

Hi I am trying to import this data http://www.oztivo.net/xmltv/7CEN_2009-04-07.xml in my mysql using your software, however it seems it cant read the xml file.

I have copied all the soruce and placed it into your demo script on this server and it works.

Can you let me know how I can get this to work in your PHP script.

Thanks

Submitted by support on Tue, 2009-04-28 11:58

Hi Russell,

At the moment, I'm just seeing some kind of compressed data being returned by that URL, and it doesn't appear to be .zip or .gz.

Are you able to currently view the XML via your web browser. I note that you implied it worked on the demo tool on this website - so that would imply perhaps that there is a transient error on the server providing the feed.

However, assuming that the source was working; and that the feed works in the demo tool, the most likely reason for it not working on your server is that URL wrappers are disabled, meaning that PHP cannot fopen() a URL (all MagicParser_parse() does is attempt to fopen() the first parameter). You can find more details of this setting on the following page:

http://uk2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

It might also be worth using the following code immediately after your call to MagicParser_parse() as this will confirm if it is a file open problem...

print MagicParser_getErrorMessage();

Hope this helps!
Cheers,
David.

Submitted by russellharrower on Tue, 2009-04-28 12:14

the file does have a .gz on the end, but it works with out that?

Submitted by support on Tue, 2009-04-28 12:23

Hi Russell,

Got it - working fine now.

If URL wrappers are enabled on your server, the problem is most likely to do with your PHP installation being unable to fopen() a gzip file. As an alternative, the file can be opened using PHP's gz file functions, the XML read into a string, and then hand the string to Magic Parser. For example:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    print 
"<p>".$record["TITLE"]."</p>";
  }
  
$url "http://www.oztivo.net/xmltv/7CEN_2009-04-07.xml.gz";
  
$fp gzopen($url,"r");
  if (!
$fp) die("Could not open ".$url);
  while(!
gzeof($fp)) $xml .= gzread($fp,1024);
  
gzclose($fp);
  
MagicParser_parse("string://".$xml,"myRecordHandler","xml|TV/PROGRAMME/");
?>

Here's the output running on this server:

http://www.magicparser.com/examples/tvguide.php

Hope this helps,
Cheers,
David.

Submitted by russellharrower on Tue, 2009-04-28 12:42

Thank you so so much.

Submitted by russellharrower on Tue, 2009-04-28 12:45

Off topic - kinda

Just wonderinf is there a PHP script that would be able to do the following

Know if a month has 30 or 31 days and knows if it is a leap year.

Submitted by russellharrower on Tue, 2009-04-28 13:18

Does anyone know what the PHP script is to show tomorrow day in YYYY-MM-DD

Submitted by support on Tue, 2009-04-28 13:27

Hi Russell,

Tomorrow in the format you require would be:

$tomorrow = date("Y-m-d",time()+86400);

You can tell the number of days in the current month with:

$days = date("t");

...and you can tell if the current year is a leap year with:

$isleapyear = date("L");

(returns 1 if it is a leap year, 0 otherwise)

Cheers!
David.

Submitted by russellharrower on Tue, 2009-04-28 13:39

David you rock.
one last question then i should be on my way to success.

the xml feed which i fetch is showing time 20090428002000 +1000
i want to turn that into 2009/04/28 00:20:00 and with the time zone i would like to change that to East-Australia

Submitted by support on Tue, 2009-04-28 13:56

Hi Russell,

Unfortunately, that format isn't recognised by PHP's strtotime() function, so the only option is to split it up, convert into a PHP standard time value (seconds since 1st Jan 1970), adjust for your timezone, and then convert into the string format required...

Try something like this:

  $time = "20090428002000 +1000";
  list($y,$m,$d,$h,$j,$s) = sscanf($time,"%4s%2s%2s%2s%2s%2s");
  $time = strtotime("$y-$m-$d $h:$j:$s");
  // convert to Eastern Australia (+10 hours)
  $time += 36000;
  $time = date("Y/m/d H:i:s",$time);
  print $time;

Cheers,
David.