Question

I want to get an alternate of an sql query WHERE field LIKE '%subStr' in PHP for example

actually I want to conditionally of different file types so I want to check whether the extension is .ppt or .pptx or .pptm .ppm or any thing else.

Was it helpful?

Solution 3

You could do it this way.

$file = 'my-file.ppt';
$parts = pathinfo($file);
$extensions = array("ppt", "pptx", "pptm", "ppm");


if (in_array($parts['extension'], $extensions)) {
   echo "we have {$parts['extension']}";
}
else {
   echo "no matches";

}

OTHER TIPS

Make use of array_pop and explode

<?php
$filename='new.newfile.ppt';
$file=explode('.',$filename);
echo $ext = array_pop($file); // ppt

You can easily strip out the last characters of a filename string to achieve this:

<?php

$filename = "myFile.txt";
$pathinfo = pathinfo($filename);
$extension = $pathinfo['extension'];

switch ($extension) {
    case "ppt":
        echo "Extension is .ppt";
        break;
    case "txt":
        echo "Extension is .txt";
        break;
}
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top