businessman332211@hotmail.com Posted July 6, 2006 Share Posted July 6, 2006 What am I doing wrong here $funnyurl = $site . $funnyurl;if (preg_match("/[.txt]{4}/i", $funnyurl)){require_once("./includes/view_text.php");}else if (preg_match("/[.jpg|.gif|.jpeg|.bmp|.tiff]{4}/i",$funnyurl)) {require_once("./includes/view_picture.php");}else if (preg_match("/[.mov]{4}/i",$funnyurl)) {require_once("./includes/view_quicktime.php");}else if (preg_match("/[.ram|.rm|.ra|.rpm]{4}/i",$funnyurl)) {require_once("./includes/view_realmedia.php");}else if (preg_match("/[.asf|.wma|.wmv|.wma|.wm|.asf|.avi|.mpeg|.mpg|.mp2|.mp3|.mid|.midi|.wav]{4}/i",$funnyurl)) {require_once("./includes/view_windowsmedia.php");}else if (preg_match("/[.swf|.swc|flv]{4}/i",$funnyurl)) {require_once("./includes/view_flash.php");}else {echo "No file exists at this location";} http://www.funnyemailforwards.com/display.phpThe problem is currently, it shows a media player file it shouldn't were did I misformat my code? Link to comment Share on other sites More sharing options...
businessman332211@hotmail.com Posted July 6, 2006 Author Share Posted July 6, 2006 I found some issues and fixed them but it's still having the same problem any advice <?php$funnyurl = $site . $funnyurl;if (preg_match("/[.txt]{4}/i", $funnyurl)){require_once("./includes/view_text.php");}elseif (preg_match("/[.jpg|.gif|.jpeg|.bmp|.tiff]{4}/i",$funnyurl)) {require_once("./includes/view_picture.php");}elseif (preg_match("/[.mov]{4}/i",$funnyurl)) {require_once("./includes/view_quicktime.php");}elseif (preg_match("/[.ram|.rm|.ra|.rpm]{4}/i",$funnyurl)) {require_once("./includes/view_realmedia.php");}elseif (preg_match("/[.asf|.wma|.wmv|.wma|.wm|.asf|.avi|.mpeg|.mpg|.mp2|.mp3|.mid|.midi|.wav]{4}/i",$funnyurl)) {require_once("./includes/view_windowsmedia.php");}elseif (preg_match("/[.swf|.swc|.flv]{4}/i",$funnyurl)) {require_once("./includes/view_flash.php");}else {echo "No file exists at this location";}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2006 Share Posted July 6, 2006 I believe the problem is the {4} after each pattern, which tells it to match exactly 4 characters. .tiff and .ra do not have 4 characters, neither do .mpeg or .midi. If you want to use regular expressions, remove the {4} and replace it with a dollar sign to anchor the pattern to the end of the string.(preg_match("/[.mov]$/i",$funnyurl))Or you can just parse out the extension yourself, and use a switch statement: $chunks = explode(".", $funnyurl);$ext = $chunks[count($chunks) - 1];switch ($ext){ case 'txt': require_once("./includes/view_text.php"); break; case 'jpg': case 'gif': case 'jpeg': case 'bmp': case 'tiff': require_once("./includes/view_picture.php"); break;... default: echo "No file exists at this location"; break;} Link to comment Share on other sites More sharing options...
businessman332211@hotmail.com Posted July 6, 2006 Author Share Posted July 6, 2006 Ah thank you, the $ situation worked perfectly, I also learnt something new about reg exps. Thanks for the help. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now