dzhax Posted April 24, 2013 Share Posted April 24, 2013 (edited) So I am working on a mass availability php script. What it does is it runs through a list of domain names the user provides and checks to see if any of them are available for registration or not by checking its who-is information. It is basically working until I print out the findings <?php$extensionList = "com-org-net-info-tv"; if(!isset($_POST['Submit'])) { echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">' . 'Please type each domain one per line without the extension:<br/>' . '<textarea name="domains" rows="20" cols="63"></textarea><br />' . '<input type="submit" name="Submit" value="Submit">' . '</form>';} else { $domains = explode("\n", str_replace(array("\r\n", "\r"), "\n", $_POST['domains'])); $extension = explode("-",$extensionList); echo "<table>" . "<tr id='header'>" . "<td class='head'>Domain</td>"; foreach($extension as $ext) echo "<td class='head'>" . $ext . "</td>"; echo "</tr>"; foreach($domains as $domain) { $outResult = is_avail($domain, $extensionList); $result = explode(" ", $outResult); $availCount = 0; foreach($result as $addRes) if($addRes == 1) $availCount++; echo "<tr name='"; if($availCount > 0) echo 'avail'; else echo 'not'; echo "'><td>" . $domain . "</td>"; $i = 0; foreach($result as $list) if($list == "1") echo "<td>Yes</td>"; else echo "<td>No</td>"; $i++; echo "</tr>"; } echo "</table>"; }function is_avail($domain, $extList) {$combResult = "";$extensions = explode("-", $extList);foreach($extensions as $extension){ $pieces = explode(".", $domain.".".$extension); $server = (count($pieces) == 2) ? $pieces[1] : $pieces[1] . "." . $pieces[2]; $server .= ".whois-servers.net"; $fp = fsockopen($server, 43, $errno, $errstr, 10); $result = ""; if($fp === FALSE) return FALSE; fputs($fp, $domain . "\r\n"); while(!feof($fp)) $result .= fgets($fp, 128); fclose($fp); $output = (stristr($result, 'no match for') !== FALSE) || (strtolower($result) == "notfound\n") ? "1" : "0"; $combResult .= $output . " "; } $combResult = $domain . " " . $combResult; return($combResult);}?> When it prints I am getting 2 extra responses from each Domain name. I am not sure where it is coming from. example output: Domain com org net info tvwatchtbr No No No No No Yes Nogiboard No Yes No Yes No Yes No ^^^^ not turning out how i would like it but basically the second yes and no are there with no "header" row to explain what it means. EDIT: Now that im reading this i have removed: $combResult = $domain . " " . $combResult; and now I only have 1 extra result. but still not sure how to get rid of it Edited April 24, 2013 by dzhax Link to comment Share on other sites More sharing options...
justsomeguy Posted April 24, 2013 Share Posted April 24, 2013 Trim the value that gets returned from the is_avail function, it has an extra space on the end. Link to comment Share on other sites More sharing options...
Ingolme Posted April 24, 2013 Share Posted April 24, 2013 Why are you making $extensionList a string instead of an array? Link to comment Share on other sites More sharing options...
dzhax Posted April 25, 2013 Author Share Posted April 25, 2013 thanks justsomeguy, that did it. as for using a string instead of an array? I am eventually going to define that extensions on the original page and send the domains and extensions to this page via an ajax connection. sending a string vs an array seemed easier. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now