replace trim( $k , '.php' ) with basename( $k , '.php' )

It fixes a bug