3

Let's say I have a registration form with email validation for college edu email addresses only set up.

What would be the best way to get the college name using PHP from that to insert into the database?

The only way I can think of is to use if college.edu address, then name = college. But there are thousands of colleges and that doesn't seem efficient.

ajreal
  • 46,720
  • 11
  • 89
  • 119
Jack
  • 31
  • 1

3 Answers3

1

Take the string containing the email value and split it at the "@" and then at the ".". If the third object of the resulting array equals edu, then add the second object of the array to your database.

Would that work for you or am I misunderstanding your inquiry?

Robert
  • 8,717
  • 2
  • 27
  • 34
  • Thanks for the quick response! The mental block that I am having is that most college email domains aren't formatted or are abbreviated and I was having trouble trying to figure out how to get the right formatting out of the email address without having to type out 2000 colleges. The only ways I can think to do it is to have an array with the name and domain, which would require me to type out 2000 anyways, or having users have to request to add a college which is a different animal all together – Jack Aug 10 '11 at 18:01
1

I'm not familiar with .edu top level domains but I presume registrants are required to provide valid information in their whois records, so a regular whois search could be a starting point. For instance, http://whois.domaintools.com/stanford.edu displays this:

Domain Name: STANFORD.EDU

Registrant:
   Stanford University
   The Board of Trustees of the Leland Stanford Junior University
   241 Panama Street, Pine Hall, Room 115
   Stanford, CA 94305-4122
   UNITED STATES

Of course, the problem is finding a search provider that will accept automated queries.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0

Try this function:

function getDomainParts($email) { 
    $posDom = strrpos($email, "@");
    $posTLD = strrpos($email, ".");
    return array( 
        "tld" => substr($email, $posTLD+1),
        "domain" => substr($email, $posDom+1, $posTLD-$posDom-1)
    );
}

$tests = array(
    "test1@college.edu",
    "test2@bobstruckingacademy.edu", 
    "test3@test.com"
);

foreach($tests as $k => $v) {
    $temp = getDomainParts($v);
    if($temp['tld'] == "edu") 
        echo("College: " . $temp['domain'] . "<br>");
    else
        echo("Not Edu Address: " . $v . " (" . $temp['tld'] . ")<br>");
}

Output:

College: college

College: bobstruckingacademy

Not Edu Address: test3@test.com (com)

I understand that this probably won't get you exactly what you are asking. If I put in MSU (as an example) does that mean Misouri State? Mississippi State? Michigan State? Without a lookup array or table of some kind, 'msu' is as good as your registration form can get.

Alternatively, you could provide a drop down that contains all colleges and have the user select one, but then again you're still resorting to typing out all of the college names.

Edit

This link may help you: List of edu Domains

Community
  • 1
  • 1
Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96