Jump to content

Check wildcard URL


rhyspaterson

Recommended Posts

Hey guys,

 

I'm looking for a function that will help me determine whether or not a URL entered by a user matches specific requirements. This is done using $_POST.

 

Basically the format of the URL must be either: www.example.com, *.example.com, www.example.*, or *.example.* - or some kind of combination such as www.url.com*. I don't want to allow a star in the 'url'.

 

So in theory, to check this, all i would have to do is make sure the string contains:

 

[www and/or *].[text].[text and/or *]

 

I think my theory is correct..? Could anyone please help me out with this function?

 

Thanks heaps lads :D

Link to comment
Share on other sites

Using regex should work?

 

$url = $_POST['url']; // do stripslashes and other cleaning here probably

if (preg_match('/(www\.example\.com|www\.example\..+|.+\.example\..+)/i',$url))
{
  // It matched
}

 

in regex . means match anything, the + is a quantifier of 1 or more, stuff inside parenthesis separated by pipe is basically "or"  (a|b|c).. special chars like . and / needs to be escaped with \, so a \. means literal .

 

regex can be complex stuff but for this task it should be pretty simple..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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