Extract name, season and episode from tv show filename

I have file names like Tv.Show.Name.S01E02.somthing.not.needed.avi

How can I extract it to get individual variables, for example:

  • $ name - Tv Show Name (no dots)
  • $ season - 1 (if leading zero ignores it)
  • $ episode - 2 (if the leading zero ignores it)
+3
source share
1 answer

I would do it like this:

if (preg_match("'^(.+)\.S([0-9]+)E([0-9]+).*$'i",$filename,$n))
{
    $name = preg_replace("'\.'"," ",$n[1]);
    $season = intval($n[2],10);
    $episode = intval($n[3],10);
}
+7
source

All Articles