Search code examples
phptranscode

Problems with matching up PHP strings


I am making a page that transcodes videoes to different formats. My problem is that I want to skip transcoding mp4 files to mp4. So I have exploded the file extension and that works nicely. I am renaming the files I transcode with an added parameter - the file extension of the original. However when I try to create an if test like under it won't fire.

if ($format != "mp4")
{
  transcodeToMp4($file, $format);
}

This won't work. So I've been search for alternative ways of solving this:

if (strpos($format, "mp4") === FALSE) 
{
  transcodeToMp4($file, $format);
}

Anyone have any idea why this won't fire? I get the correct string for the extension in the filename though.

$format = strtolower(end(explode(".",$file)));

Solution

  • Better use pathinfo to get the extension:

    if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) != 'mp4') {
        transcodeToMp4($file);
    }