NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page How to add a sub domain in this PHP array?

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-07-2007, 04:29 PM THREAD STARTER               #1 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Question How to add a sub domain in this PHP array?


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.
????: NamePros.com http://www.namepros.com/code/302379-how-add-sub-domain-php-array.html

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

Quote:
<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|a t|be|bz|ch|cn|de|es|eu|fm|gs|im|in|io|jobs|jp|la|l i|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 by YesBrilliant; 03-12-2007 at 11:22 AM.
YesBrilliant is offline  
Old 03-07-2007, 05:33 PM   #2 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



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...
TwistMyArm is offline  
Old 03-07-2007, 06:22 PM THREAD STARTER               #3 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



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...
YesBrilliant is offline  
Old 03-08-2007, 05:10 PM THREAD STARTER               #4 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Anyone?


.
YesBrilliant is offline  
Old 03-08-2007, 07:20 PM   #5 (permalink)
NamePros Member
Join Date: Jun 2006
Posts: 195
tanfwc is an unknown quantity at this point
 



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?
tanfwc is offline  
Old 03-08-2007, 08:45 PM THREAD STARTER               #6 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Originally Posted by tanfwc
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


????: NamePros.com http://www.namepros.com/showthread.php?t=302379
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 by YesBrilliant; 03-08-2007 at 09:02 PM.
YesBrilliant is offline  
Old 03-10-2007, 10:48 AM THREAD STARTER               #7 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Anyone could help, please?

Thanks.


.
YesBrilliant is offline  
Old 03-10-2007, 12:41 PM   #8 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



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...
TwistMyArm is offline  
Old 03-11-2007, 06:47 PM THREAD STARTER               #9 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Originally Posted by TwistMyArm
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.
YesBrilliant is offline  
Old 03-11-2007, 07:25 PM   #10 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



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...
TwistMyArm is offline  
Old 03-11-2007, 10:09 PM THREAD STARTER               #11 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



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.
YesBrilliant is offline  
Old 03-12-2007, 08:03 AM   #12 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



Originally Posted by YesBrilliant
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.
????: NamePros.com http://www.namepros.com/showthread.php?t=302379

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...
TwistMyArm is offline  
Old 03-12-2007, 12:06 PM THREAD STARTER               #13 (permalink)
Account Closed
Join Date: Sep 2006
Posts: 1,075
YesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to allYesBrilliant is a name known to all
 



Smile 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.

Quote:

<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)
{
????: NamePros.com http://www.namepros.com/showthread.php?t=302379
$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>
YesBrilliant is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:59 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger