brandensmith1 Posted February 8, 2008 Share Posted February 8, 2008 I'm making an account settings page for my website and I want to set up a preg to check if the url they give for their profile image ends with gif/jpg/jpeg/bmp/or png. I'm really new to preg_matching and already ran into a problem because I noticed pages sometimes have more than just 2-3 periods so I can't just make the preg check for the word after a period. I jumbled around what I know about preg_match and preg_match_all and tried to make a way to count the amount of periods in the url then get the last word after the last period but I am not sure if what I am attempting is possible. What I attempted which might make you pros cringe is this... if($_POST['getimg'] != '' || $_POST['getimg'] != ' ') { $bambo = ' '; preg_match_all('/\./i', $_POST['getimg'], $jambo, PREG_PATTERN_ORDER); for($i = 0; $i <= $jambo[0]; $i++) { $baloo = '(\*)+\.'; //keep adding the preg info to $bambo for the amount of periods there are $bambo = $bambo.$baloo; } if(!preg_match('/^(http:\/\/\)+($bambo)?{2,4}$/i', $_POST['getimg'], $match)) { //error message $thepage = 'Format is:<br>http://www.page.com/img.type'; } else { if($match == 'gif' || $match == 'jpg' || $match == 'jpeg' || $match == 'bmp' || $match == 'png') { //add the url to the image section for the user in the database } else { $thepage = 'Allowed filetypes:<br>gif, jpg, jpeg, bmp, png'; } } } Is there anyway to salvage what I did to make it work or is there a link someone could relay me to that might be able to help? I've been stuck on this for a few days. Link to comment https://forums.phpfreaks.com/topic/90016-solved-preg_match/ Share on other sites More sharing options...
sasa Posted February 8, 2008 Share Posted February 8, 2008 try <?php $a ='asd.grrt//fdgfdh/gnggf.j/fdh.ztu.htu.lll'; preg_match('/\.([^\.]+)$/',$a,$b); print_r($b); ?> Link to comment https://forums.phpfreaks.com/topic/90016-solved-preg_match/#findComment-461556 Share on other sites More sharing options...
brandensmith1 Posted February 8, 2008 Author Share Posted February 8, 2008 Oh haha I knew I was doing something wrong. Yeah $b[1] returns the filetype thank you Link to comment https://forums.phpfreaks.com/topic/90016-solved-preg_match/#findComment-461570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.