Hey guys,

I am wanting to find to see if a variable is in the array:

Here is my code:

$domainlist = array(".com.au",".com",".co.nz",".net.au",".net",".net.nz",".org.au",".org",".org.nz");

$serverlist = array(
".co.nz=whois.srs.net.nz|220 Available",
".com=whois.crsnic.net|No match for",
".net=whois.crsnic.net|No match for",
".org=whois.publicinterestregistry.net|NOT FOUND",
".com.au=whois.aunic.net|No Data Found",
".net.au=whois.aunic.net|No Data Found",
".org.au=whois.aunic.net|No Data Found",
);

foreach ($serverlist as $item) {
		$server_un = explode("=", $item);
		
		print"<pre>";
		print_r($server_un);
		print"</pre>";
		
		if (strstr($server_un, $tld)) {
			print 1;	
		}
	}

Could you guys please tell me how i could get the server and the server data (after the |) to two separate variables 1 called (server) and other called (Server Data)


Thanks,
Marais

if you are looking for $tld in your server list then you can do it directly

$serverlist=array(........);.//your serverlist array

$tld="org";

$key = array_search($tld, $array); 

echo $key;//returns 3

Thanks for that, i figured it out before this post,
Thanks here is the code that worked.

<?php

$domainlist = array(".com.au",".com",".co.nz",".net.au",".net",".net.nz",".org.au",".org",".org.nz");

$serverlist = array(
".co.nz=whois.srs.net.nz|220 Available",
".com=whois.crsnic.net|No match for",
".net=whois.crsnic.net|No match for",
".org=whois.publicinterestregistry.net|NOT FOUND",
".com.au=whois.aunic.net|No Data Found",
".net.au=whois.aunic.net|No Data Found",
".org.au=whois.aunic.net|No Data Found",
);

function checkDomain($domain, $tld){
	global $serverlist;

	foreach ($serverlist as $item) {
		$server_un = explode("=", $item);
		
		if ($server_un[0] == $tld) {
			$server_un2 = explode("|", $server_un[1]);
			$server = $server_un2[0];
			$findText = $server_un2[1];
		}
	}
	
	// Open a socket connection to the whois server
	$con = fsockopen($server, 43);
	if (!$con) return false;
	
	// Send the requested doman name
	fputs($con, $domain."\r\n");
	
	// Read and store the server response
	$response = ' :';
	while(!feof($con)) {
		$response .= fgets($con,128); 
	}
	
	// Close the connection
	fclose($con);
	
	// Check the response stream whether the domain is available
	if (strpos($response, $findText)){
		return true;
	}
	else {
		return false;   
	}
}

function showDomainResult($domain, $tld){
   if (checkDomain($domain, $tld)){
	  $values = $values. "<tr><td>".$domain."</td><td>AVAILABLE</td></tr>";
   }
   else $values = $values. "<tr><td>".$domain."</td><td>REGISTERED</td></tr>";
   return $values;
}

function showTld($domains) {
	$x=0;
	$checked = "";
	$columns = 3;
	foreach($domains as $key => $value) {
		if ($x==0) {
			$values = $values."<tr>";	
		}
		if ($x==$columns) {
			$values = $values."</tr>";
			$x=0;
		}
		if (isset($_REQUEST['tlds'])) {
			if (in_array($key, $_REQUEST['tlds'])) {
				$checked = "checked";
			} else {
				$checked = "";	
			}
		}
		$values = $values."<td><input type=\"checkbox\" value=\"".$key."\" name=\"tlds[]\"".$checked.">".$value."</td>";
		$x++;
	}
	return $values;
}

function showResults($domains) {
	$domainbase = (isset($_REQUEST['domainname'])) ? $_REQUEST['domainname'] : '';
	$values = '<table width="100%">';
	
	foreach ($_REQUEST['tlds'] as $items) {
		if (strlen($domainbase)>2){
			if (isset($_REQUEST['tlds'])) { 
				$tlds = $domains[$items];
			   	$values = $values.showDomainResult($domainbase.$tlds, $tlds);	
			}
		}	
	}
	
	$values = $values.'</table>';
	
	return $values;
}
?>

Thanks,
Marais

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.