Strpos not getting the correct result in condition

70 Views Asked by At

Hi Im having trouble trying to get it output towards the right condition, but right now its prompting into the else statement, instead of the the if statement, when I output the for each statement, it managed to output the files in the directory but I just cant get the string with matching filename even though the string matches it. My current output would be here2. When i checked for the output in $res, it would be empty.

    if(strpos($var, "TL")!== false){
        foreach($dirIL as $file1){
            if(strpos( $file1 , $pattern) !== false){
                $res = $filePath .'IL\\' . $file1;
                return $res;
            } else{
                $fullPSPath = "PS File Not Found";
                //return $fullPSPath;
                return "here2"; //keeps returning this despite having a matching file name.
                }
            }
    } else {
        foreach($dirUL as $file2){
            if(strpos($file2, $pattern) !== false){                     
                $res = $filePath .'UL\\' . $file2;
                //return $res;
                return "here3";
            } else{
                $res = "PS File Not Found";
                //return $res;
                return "here4";
                }
            }
0

There are 0 best solutions below