Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    wildcard a domain string

    Hi

    This works, but I would rather do something like in #2 example
    PHP Code:
    if ( $_SERVER['SERVER_NAME'] != ' www.domain.com' 
    I'm trying to wildcard * everything in front of domain.com
    PHP Code:
    if ( $_SERVER['SERVER_NAME'] != ' * .domain.com' 
    also if someone knows a better way to check a domain can
    you please let me know?.

    Thanks
    Sonny
    Last edited by sonny; 12-03-2011 at 03:16 AM.

  • #2
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts
    are you trying to validate it with a specific domain name or just need to validate that it is a domain name?
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Chris Hick View Post
    are you trying to validate it with a specific domain name or just need to validate that it is a domain name?
    With a specific domain name, and trying to wildcard anything in front of domain.com, like
    Code:
    www.domain.com
    domain.com
    http://domain.com
    Sonny

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Not tested:
    PHP Code:
    if(preg_match('/.*somedomain\.com$/si'$_SERVER['SERVER_NAME']))
        echo 
    'matched';
    else
        echo 
    'not matched'
    You could also use strpos(), which would be faster, if you aren't concerned with the possibility of it being matched elsewhere in the string.

  • #5
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Thanks! Happy Holidays, I am marking solved (works)

    but on a side note, do you think the performance issue of preg_match
    outweighs the odds of someone just using htttp://domain.com?

    Thanks again
    Sonny

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by sonny View Post
    but on a side note, do you think the performance issue of preg_match
    outweighs the odds of someone just using htttp://domain.com?
    Not sure what you mean there. The performance difference of using preg_match() isn't major, we are talking about milliseconds. Either way, it's up to you to decide which method is ideal for your purposes.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •