IT.COM

How to add a sub domain in this PHP array?

Spaceship Spaceship
Watch

YesBrilliant

Account Closed
Impact
38
Hi,

This is a basic question but I have no experience with coding in PHP, hope you understand.

I have an array/list of extensions and need to include the subdomain extension .org.uk but I can not do it right.

This is the original code, a domain list cleaner script:

<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(" +", $domains);
foreach ($list as $value)
{
preg_match("/[a-z-A-Z0-9-]+\.(com|net|org|us|biz|info|cc|ca|br|tv|ac|ag|am|at|be|bz|ch|cn|de|es|eu|fm|gs|im|in|io|jobs|jp|la|li|mn|mobi|ms|name|nl|pl|ru|sc|se|sg|sh|tc|tk|tm|tw|vc|vg|uk|ws)/", $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 size="45" type="submit" value="Submit">
</form>
</center>
</body>
</html>

Can anyone help me, please?

Thanks in advance.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
You probably just want to add 'org\.uk' to your list (without the quotes). Periods are special in regexps so you need to escape them with a backslash when you want to use one normally...
 
0
•••
Thanks TwistMyArm,

I did that but it keeps deleting the UK from the results. The DOT is interfering with some part in the script.

Still looking for a solution...
 
0
•••
0
•••
Well, I can't understand what you trying to do. Maybe you like to explain to me in more detail so I can assist you on the problem?
 
0
•••
tanfwc said:
Well, I can't understand what you trying to do. Maybe you like to explain to me in more detail so I can assist you on the problem?
Thanks for the support.

What I need is to include the extension org.uk in that sequence of top TLDs, which are listed Without the "." in front of them. The extension org.uk has a "." between the org and the uk, what interferes in the results.

That script is a Domain List Cleaner where all characters/words that are not part of a domain then are excluded from the results. The way the list is now make domains like test.org.uk to be excluded as well, when they shoudn't.

For example, the way the script is now, an example list like:
1. test.com
2 . test.net zxzx zxz.xzxzxz
3. test.org.uk
4. test.ca .kjkjk
5. 4444 test.us
1212121212112


would return only:
test.com
test.net
test.ca
test.us


thus also excluding the test.org.uk domain as garbage simply because it has a "." in there.

So the question: How to include the org.uk in that sequence of top TLDs?

Your help is appreciated.
 
Last edited:
0
•••
Anyone could help, please?

Thanks.


.
 
0
•••
Oh, I think I see the problem... the .org part is matching before the regexp can match it with .org.uk. You could probably play with the greediness of the regexp, but it might just be easier to add 'org.uk' BEFORE the 'org' option...
 
1
•••
TwistMyArm said:
but it might just be easier to add 'org.uk' BEFORE the 'org' option...
Thanks,

I tried to do that but it gets worst. As I don't know more of coding I'll leave it the way it is.

Thanks anyway.
 
0
•••
Strange. With your sample data, it worked for me.

Copy your code here as it stands right now, as well as your sample data again and that way we can be sure there's been no mistyping...
 
0
•••
I just updated the first post the way I am using now.

However, still getting incorrect results. I also tried to put the org.uk in the start of the sequence but same error.

Another example, checking:
wwwwwwwww.org.uk
wwwwwwwww.co.uk
wwwwwwwww.org
wwwwwwwww.com
wwwwwwwww.ws


Returns only:
wwwwwwwww.org.uk
wwwwwwwww.org


Thanks again, I really appreciate your help.

Mark.
 
0
•••
YesBrilliant said:
I just updated the first post the way I am using now.

Please, don't do that. Firstly, other people that come to the thread are going to see your (current) code, then get confused when I start making suggestions to do things that you already apparently did.

Secondly, unless you have that original code somewhere, you're going to have to take my word for it that with that sample set, your original code did the same thing :)

The problem that you experienced there is related not to the regular expression being used to match, but the regular expression you're using to split. The split assumes that you have a space on the line: newlines were not being considered...

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

with:
$list = split("[[:space:]]+", $domains);

and see how it goes...
 
0
•••
Working!!!

Hey, Great! It IS working perfectly now!!!

I even included some other extensions and subdomains assigned by the registry and all went all again!

You can see the Final script below. The first post now returned to the Original script.

Thanks a lot, TwistMyArm! You are a great NP member!!!

Sent you a PM.

<html>
<head>
<title>Domain List Cleaner</title>
<body>
<center>
<form method="post" action="">
<textarea name="domains" rows="10" cols="40">
<?php
$temparray = array();
$domains = $_POST['domains'];
if ($domains)
{
$list = split("[[:space:]]+", $domains);
foreach ($list as $value)
{
preg_match("/[a-z-A-Z0-9-]+\.(co.uk|org.uk|com.br|org.br|net.br|on.ca|bc.ca|ab.ca|qc.ca|com|net|org|us|biz|info|ac|ag|am|at|be|bz|ca|cc|ch|cn|de|es|eu|fm|gs|im|in|io|jobs|jp|la|li|mn|mobi|ms|name|nl|pl|ru|sc|se|sg|sh|tc|tk|tm|tv|tw|vc|vg|ws)/", $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="Get a Clean Domain List!">
</form>

</center>

</body>
</html>
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back