rhyspaterson Posted July 5, 2007 Share Posted July 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/58494-check-wildcard-url/ Share on other sites More sharing options...
stoker Posted July 5, 2007 Share Posted July 5, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/58494-check-wildcard-url/#findComment-290092 Share on other sites More sharing options...
rhyspaterson Posted July 5, 2007 Author Share Posted July 5, 2007 Thanks muchly stoker, will look into it Quote Link to comment https://forums.phpfreaks.com/topic/58494-check-wildcard-url/#findComment-290118 Share on other sites More sharing options...
sasa Posted July 5, 2007 Share Posted July 5, 2007 try <?php $a = 'wwW*.sasa.l*'; if(preg_match('/^(www|\*)[\*]?\.[a-z0-9]+\.([a-z0-9]+|\*)[\*]?$/i',$a,$b)) echo 'OK'; else echo 'NO'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/58494-check-wildcard-url/#findComment-290160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.