/ Published in: PHP
I use this little guy to get the width and height from a filename. Often when I need to show a flash swf file I don't have an easy way to tell the width and the height of the file for display. However is the file name is "some_flash_file 300x250.swf" then this litte guy will help a lot.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * * Function: getWH * Description: Return the width and height from a given string * * Param: $f a string that hopefully has ###x### some where in it * * Caveat: This will not work on every single file name ever conceived by man. * ex, something45x77x88x90x13.jpg not only is a stupid name for a file * but will foobar this function. * **/ function getWH( $f ) { // First we get the height by stripping off the numbers that follow an 'x' $height = $matches[1]; // Next we reverse the string and do the same thing for the width // Probably there exists a better regular expression to do it in one step. // Then again there is probably a regular expression that can cure world hunger // Maybe someday I will figure out both! $dims[0] = $width; $dims[1] = $height; return $dims; // return a simple array }
URL: http://www.itsgotto.be/cv.php