Name.com Cyber Monday sale: $6.99 .com domains and more. Shop the sale.

Simple Domain List Cleaner in PHP

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Namecheap AuctionsNamecheap Auctions
Watch

deadserious

Established Member
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
so if i was to enter

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

it would remove the first bob.com?
 
0
Close
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
Close
ah right wicked!

thats a handy little script
 
0
Close
nice! looks like a sweet little script, gonna give it a try.. thanks!
 
0
Close
nice script there..thanks :tu:
 
0
Close
very nice code... i think i might use it :)
 
0
Close
hmm. what happens if there are several valid domains in one line?
 
0
Close
thats what i was thinking as well.... I'll try to fix that ;)
 
0
Close
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
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back