IT.COM

Simple Domain List Cleaner in PHP

Spaceship Spaceship
Watch
Impact
6
This simply extracts the first occurence of a domain name from every line you enter in the textarea and only prints the domain once if it occurs on multiple lines. You can change the regex to better suit your needs. I have it the way it is to prevent it from matching things such as file.php or file.gif if you enter a bunch of source code or something. B-)

PHP:
<html> 
<head> 
<title>Domain List Cleaner</title>

<body>

<center> 
<form method="post" action="">
<textarea name="domains" rows="15" cols="60">
<?php
$temparray = array(); 
$domains = $_POST['domains'];
if ($domains)
{
	$list = split("\r\n", $domains); 
	foreach ($list as $value) 
	{ 
		preg_match("/[a-z-A-Z0-9-]+\.(com|net|org|us|biz|info|cc)/", $value, $matches); 
        
		for ($i = 0; $i < count($matches); $i++) 
		{ 
			array_push($temparray, $matches[0]);
		} 
	}
	
	$uniquearray = array_unique($temparray);

	foreach ($uniquearray as $uniquevalue) 
	{
		echo "$uniquevalue\n";
	} 
}
?>
</textarea>
<br />
<input type="submit" value="Process">
</form>
</center>

</body>
</html>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
so if i was to enter

bob.com
bob.org
bob.net
bob.com

it would remove the first bob.com?
 
0
•••
Yes it would, or actually the second :D

Here's the results for pasting the entire html source code from the namepros.com homepage:

namepros.com
TD.info
vBStyles.net
google.com
DomainEmpire.com
CoolHost.com
googlesyndication.com
qksrv.net


B-)
 
0
•••
ah right wicked!

thats a handy little script
 
0
•••
nice! looks like a sweet little script, gonna give it a try.. thanks!
 
0
•••
nice script there..thanks :tu:
 
0
•••
very nice code... i think i might use it :)
 
0
•••
hmm. what happens if there are several valid domains in one line?
 
0
•••
thats what i was thinking as well.... I'll try to fix that ;)
 
0
•••
Originally posted by armstrong
hmm. what happens if there are several valid domains in one line?
If you change this line:

$list = split("\r\n", $domains);

to something like this:

$list = split(" +", $domains);

That might do it
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back