[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming > CODE

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.


Closed Thread
 
LinkBack Thread Tools
Old 03-07-2007, 03:29 PM   #1 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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.

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 10:22 AM.
YesBrilliant is offline  
Old 03-07-2007, 04:33 PM   #2 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 05:22 PM   #3 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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, 04:10 PM   #4 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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, 06:20 PM   #5 (permalink)
NamePros Member
 
Join Date: Jun 2006
Posts: 195
36.90 NP$ (Donate)

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, 07:45 PM   #6 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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


Quote:
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


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 08:02 PM.
YesBrilliant is offline  
Old 03-10-2007, 09:48 AM   #7 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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, 11:41 AM   #8 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 05:47 PM   #9 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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


Quote:
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, 06:25 PM   #10 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

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, 09:09 PM   #11 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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, 07:03 AM   #12 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

TwistMyArm is on a distinguished road


Quote:
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.

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, 11:06 AM   #13 (permalink)
Account Closed
 
Join Date: Sep 2006
Posts: 1,075
365.60 NP$ (Donate)

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)
{
$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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 01:56 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85