Regex Extension comparer

/ Published in: PHP
Save to your folder(s)

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...

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.