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 3 of 3

Thread: asp to php

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,464
    Thanks
    15
    Thanked 0 Times in 0 Posts

    asp to php

    can someone help me translate the following code from asp to php:

    emailhost=Mid(email, InStr(Email, "@") + 1)
    n=instrrev(emailhost,".")
    domainend=right(emailhost,len(emailhost)-n)
    domainend=lcase(domainend)

    select case domainend
    case "edu","com","net","us","info","org","biz,".cc"
    domainvalid=true
    case else
    filtered=1
    end select

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    list($email$hostname) = explode("@"$email);
    list(
    $name$type) = explode(".",$hostname);

    switch(
    $type)
    {
    case 
    "edu";
    case 
    "com";
    case 
    "net";
    case 
    "us";
    case 
    "info";
    case 
    "org";
    case 
    "biz";
    case 
    "cc"$domainvalid=true; break;
    default;
    $filtered=1;

    think that should be close

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    ok, it seems to me that all you're trying to do is check that everything in the string after the last . is one of those in your list.
    This is what I would do - throwing in checking for the @ too
    PHP Code:
    if(strpos(email"@")!==false)
    {
       
    $emailParts explode("."$email);
       
    $domain strtolower($emailParts[count($emailParts)-1]);
       
    $allowedDomains = array("edu","com","net","us","info","org","biz","cc");
       if(
    in_array($domain$allowedDomains))
        {
          
    $domainValid true;
         }
         else
           {
              
    filtered 1
            
    }
     } 


  •  

    Posting Permissions

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