Jump to content

[SOLVED] preg_match


brandensmith1

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.