Posted By

Oldarney on 12/13/09


php fast inarray quick extension alternativelist

Versions (?)

Regex Extension comparer

 / Published in: PHP

I whipped this up after finding that my worst fears were true, pathinfo is slow. Top that with in_array and you've got your self some heavy code. Nothing like regex to speed things up.

This little code checks the extension of a path to see if it is a desired extension.

EDIT: the regex engine kills any speed benefits...

  1. <?php
  3. if (preg_match('/.*\.(xls|jpg)\z/',substr('the image/is on/fire.jpg,-4'))){
  4. echo 'true';
  5. }
  7. ?>

Report this snippet  

You need to login to post a comment.