PHP: Can this work (Array)

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Xodiaq

Established Member
Impact
0
HI, here is some code I was thinking of earlier

PHP:
<?php

$i=1

$ext[1] = "one";
$ext[2] = "two";
$ext[3] = "three";
$ext[4] = "four";
$ext[5] = "five";


while($i<=5)
{
echo $ext[$i] "\n";
$i++;
}

?>

Can this work in any way? I do not have an enviroment for testing PHP at the min. So I would appreciate any help
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
I am not exactly sure what you are trying to achieve, but yes it can work. There are some minor issues but the basic code will work.
PHP:
<?php 
    $i=1;

    $ext[1] = "one"; 
    $ext[2] = "two"; 
    $ext[3] = "three"; 
    $ext[4] = "four"; 
    $ext[5] = "five"; 

    while ($i<6) echo $ext[$i++]."\n";
?>
 
0
•••
Chael said:
HI, here is some code I was thinking of earlier

PHP:
<?php

$i=1

$ext[1] = "one";
$ext[2] = "two";
$ext[3] = "three";
$ext[4] = "four";
$ext[5] = "five";


while($i<=5)
{
echo $ext[$i] "\n";
$i++;
}

?>

Can this work in any way? I do not have an enviroment for testing PHP at the min. So I would appreciate any help

PHP:
  <?php

$i = 1;

$ext[1] = "one";
$ext[2] = "two";
$ext[3] = "three";
$ext[4] = "four";
$ext[5] = "five";


while($i<=5)
{
echo $ext[$i]."\n";
$i++;
}

?>


That should work :)
 
0
•••
Thank you!! didnt even notice that missing ";"

Ok, got a site to test on. One question. How can I get each echo to appear on a new line? I thought that \n did that but apparently not...?
 
0
•••
Chael said:
Thank you!! didnt even notice that missing ";"

Ok, got a site to test on. One question. How can I get each echo to appear on a new line? I thought that \n did that but apparently not...?
Try <br />
 
0
•••
nope :(
 
0
•••
It's better to use foreach in a case where you wish to loop through all array elements and also with numeric arrays you should start with 0 (although not essential)

So i would have:
PHP:
$ext[0] = "one";
$ext[1] = "two";
$ext[2] = "three";
$ext[3] = "four";
$ext[4] = "five"; 

foreach($ext as $value)
{
	echo $value . '<br />';
}

(that will also fix your new line problem).

Note if you were using while for a reason, this is still a little better ;)

PHP:
for($i = 0; $i <= 4; /* count($ext) */ $i++)
{
    echo $ext[$i] . '<br />';
}
 
Last edited:
0
•••
Parse error: parse error, unexpected T_VARIABLE on line 6

thats with the foreach code... any ideas?
 
0
•••
Updated in the original post but...
PHP:
 <?php
$ext[0] = "one";
$ext[1] = "two";
$ext[2] = "three";
$ext[3] = "four";
$ext[4] = "five"; 

foreach($ext as $value)
{
    echo $value . '<br />';
} 
?>

You shouldn't be receiving a error from that.

Matt
 
0
•••
Thanks Matthew!!!

works great now. In case you were wondering what it was for is that, if you have ever been to whois.hm they have alot of supported extensions on their list but no option to check all, so I am going to set up a php script to do it for you in a bulk check.
 
0
•••
Chael said:
Thanks Matthew!!!

works great now. In case you were wondering what it was for is that, if you have ever been to whois.hm they have alot of supported extensions on their list but no option to check all, so I am going to set up a php script to do it for you in a bulk check.
Just so you know Chael, you can also use registerfly.com to bulck check different extensions, up to 500 different domains. Just tick the boxes and you're on your way :).

http://registerfly.com/domains/bytld.php

Regards,
Rhett.
 
0
•••
\n makes a new line; just not an HTML new line. If you view source on the page it was running, it would have each on a new line.

<pre><?php echo "hi\nhi"; ?></pre>
That would show up as
hi
hi
On the actual page (and viewing the source.)
 
0
•••
Matthew. said:
It's better to use foreach in a case where you wish to loop through all array elements and also with numeric arrays you should start with 0 (although not essential)

Out of interest why do you say a foreach is better? The problem with foreach over while is that foreach actually creates a new copy of the array and uses that for the loop while a while loop will use the original array and of course uses less memory.

Of course if as is in this thread you are only using a small array then the difference is negligible but if using a large array it will make a huge amount of difference.
 
0
•••
filth@flexiwebhost said:
Out of interest why do you say a foreach is better? The problem with foreach over while is that foreach actually creates a new copy of the array and uses that for the loop while a while loop will use the original array and of course uses less memory.

Of course if as is in this thread you are only using a small array then the difference is negligible but if using a large array it will make a huge amount of difference.

Actually i say it without any firm proof, so you may well be right :).

Speed wise i swear i have read somewhere that foreach is quick than a while (although not sure), and to that end using something like this:
PHP:
while(list($key, $value) == each($ext))
..is quicker.

Actually while posting, thinking about it you are right in regards to speed (however nominal it may be in this case :P)

I would still reccomend using foreach however, or even for like i posted above as it keeps the code more organised. Defining a variable outside the loop, and incrementing it inside is messier than a simple for where that can all be done within it's argument(s).

Matt
 
0
•••
Well, here it is, the final script(s) it works so dont dis it :P

whoisext.php
PHP:
<html>
<body>

<form action="urlext.php" method="post">
Domain (without www or .com Etc.):<input type="text" name="url" />
<input type="submit" />
</form>

</body>
</html>

urlext.php
PHP:
<?php

//ARRAY

$ext[1] = ".ab.ca";
$ext[2] = ".ac";
$ext[3] = ".ac.ac";
$ext[4] = ".ac.at";
$ext[5] = ".ac.be";
$ext[6] = ".ac.cn";
$ext[7] = ".ac.il";
$ext[8] = ".ac.in";
$ext[9] = ".ac.jp";
$ext[10] = ".ac.kr";
$ext[11] = ".ac.nz";
$ext[12] = ".ac.th";
$ext[13] = ".ac.uk";
$ext[14] = ".ac.za";
$ext[15] = ".ad";
$ext[16] = ".adm.br";
$ext[17] = ".adv.br";
$ext[18] = ".aero";
$ext[19] = ".af";
$ext[20] = ".ag";
$ext[21] = ".agro.pl";
$ext[22] = ".ah.cn";
$ext[23] = ".aid.pl";
$ext[24] = ".alt.za";
$ext[25] = ".am";
$ext[26] = ".am.br";
$ext[27] = ".arq.br";
$ext[28] = ".art.br";
$ext[29] = ".arts.ro";
$ext[30] = ".as";
$ext[31] = ".asn.au";
$ext[32] = ".asso.fr";
$ext[33] = ".asso.mc";
$ext[34] = ".at";
$ext[35] = ".atm.pl";
$ext[36] = ".au";
$ext[37] = ".auto.pl";
$ext[38] = ".bbs.tr";
$ext[39] = ".bc.ca";
$ext[40] = ".be";
$ext[41] = ".bg";
$ext[42] = ".bio.br";
$ext[43] = ".biz";
$ext[44] = ".biz.pl";
$ext[45] = ".bj";
$ext[46] = ".bj.cn";
$ext[47] = ".br";
$ext[48] = ".br.com";
$ext[49] = ".by";
$ext[50] = ".bz";
$ext[51] = ".ca";
$ext[52] = ".cat";
$ext[53] = ".cc";
$ext[54] = "cd";
$ext[55] = ".ch";
$ext[56] = ".ci";
$ext[57] = ".cl";
$ext[58] = ".cn";
$ext[59] = ".cn.com";
$ext[60] = ".cng.br";
$ext[61] = ".cnt.br";
$ext[62] = ".co.ac";
$ext[63] = ".co.at";
$ext[64] = ".co.il";
$ext[65] = ".co.in";
$ext[66] = ".co.jp";
$ext[67] = ".co.kr";
$ext[68] = ".co.nz";
$ext[69] = ".co.th";
$ext[70] = ".co.uk";
$ext[71] = ".co.za";
$ext[72] = ".com";
$ext[73] = ".com.au";
$ext[74] = ".com.br";
$ext[75] = ".com.cn";
$ext[76] = ".com.ec";
$ext[77] = ".com.fr";
$ext[78] = ".com.hk";
$ext[79] = ".com.mm";
$ext[80] = ".com.mx";
$ext[81] = ".com.pl";
$ext[82] = ".com.ro";
$ext[83] = ".com.ru";
$ext[84] = ".com.sg";
$ext[85] = ".com.tr";
$ext[86] = ".com.tw";
$ext[87] = ".coop";
$ext[88] = ".cq.cn";
$ext[89] = ".cri.nz";
$ext[90] = ".cx";
$ext[91] = ".cz";
$ext[92] = ".de";
$ext[93] = ".dk";
$ext[94] = ".ecn.br";
$ext[95] = ".edu";
$ext[96] = ".edu.au";
$ext[97] = ".edu.cn";
$ext[98] = ".edu.hk";
$ext[99] = ".edu.mm";
$ext[100] = ".edu.mx";
$ext[101] = ".edu.pl";
$ext[102] = ".edu.tr";
$ext[103] = ".edu.za";
$ext[104] = ".ee";
$ext[105] = ".eng.br";
$ext[106] = ".ernet.in";
$ext[107] = ".esp.br";
$ext[108] = ".etc.br";
$ext[109] = ".eti.br";
$ext[110] = ".eu";
$ext[111] = ".eu.com";
$ext[112] = ".eu.lv";
$ext[113] = ".fi";
$ext[114] = ".fin.ec";
$ext[115] = ".firm.ro";
$ext[116] = ".fm.br";
$ext[117] = ".fo";
$ext[118] = ".fot.br";
$ext[119] = ".fr";
$ext[120] = ".fst.br";
$ext[121] = ".g12.br";
$ext[122] = ".gb.com";
$ext[123] = ".gb.net";
$ext[124] = ".gd";
$ext[125] = ".gd.cn";
$ext[126] = ".gen.nz";
$ext[127] = ".gf";
$ext[128] = ".gg";
$ext[129] = ".gi";
$ext[130] = ".gmina.pl";
$ext[131] = ".go.jp";
$ext[132] = ".go.kr";
$ext[133] = ".go.th";
$ext[134] = ".gob.mx";
$ext[135] = ".gov";
$ext[136] = ".gov.br";
$ext[137] = ".gov.cn";
$ext[138] = ".gov.ec";
$ext[139] = ".gov.il";
$ext[140] = ".gov.in";
$ext[141] = ".gov.mm";
$ext[142] = ".gov.mx";
$ext[143] = ".gov.sg";
$ext[144] = ".gov.tr";
$ext[145] = ".gov.za";
$ext[146] = ".govt.nz";
$ext[147] = ".gr.gs";
$ext[148] = ".gs.cn";
$ext[149] = ".gsm.pl";
$ext[150] = ".gv.ac";
$ext[151] = ".gv.at";
$ext[152] = ".gx.cn";
$ext[153] = ".gz.cn";
$ext[154] = ".hb.cn";
$ext[155] = ".he.cn";
$ext[156] = ".hi.cn";
$ext[157] = ".hk";
$ext[158] = ".hk.cn";
$ext[159] = ".hl.cn";
$ext[160] = ".hn";
$ext[161] = ".hn.cn";
$ext[162] = ".hu";
$ext[163] = ".hu.com";
$ext[164] = ".id.au";
$ext[165] = ".ie";
$ext[166] = ".il";
$ext[167] = ".in";
$ext[168] = ".ind.br";
$ext[169] = ".inf.br";
$ext[170] = ".info";
$ext[171] = ".info.pl";
$ext[172] = ".info.ro";
$ext[173] = ".int";
$ext[174] = ".io";
$ext[175] = ".is";
$ext[176] = ".it";
$ext[177] = ".iwi.nz";
$ext[178] = ".je";
$ext[179] = ".jl.cn";
$ext[180] = ".jor.br";
$ext[181] = ".jp";
$ext[182] = ".js.cn";
$ext[183] = ".k12.il";
$ext[184] = ".k12.tr";
$ext[185] = ".ke";
$ext[186] = ".ki.";
$ext[187] = "kr";
$ext[188] = ".kz";
$ext[189] = ".la";
$ext[190] = ".lel.br";
$ext[191] = ".li";
$ext[192] = ".ln.cn";
$ext[193] = ".lt";
$ext[194] = ".ltd.uk";
$ext[195] = ".lu";
$ext[196] = ".lv";
$ext[197] = ".mail.pl";
$ext[198] = ".maori.nz";
$ext[199] = ".mb.ca";
$ext[200] = ".me.uk";
$ext[201] = ".med.br";
$ext[202] = ".med.ec";
$ext[203] = ".media.pl";
$ext[204] = ".mg";
$ext[205] = ".mi.th";
$ext[206] = ".miasta.pl";
$ext[207] = ".mil";
$ext[208] = ".mil.br";
$ext[209] = ".mil.ec";
$ext[210] = ".mil.nz";
$ext[211] = ".mil.pl";
$ext[212] = ".mil.tr";
$ext[213] = ".mil.za";
$ext[214] = ".mn";
$ext[215] = ".mo.cn";
$ext[216] = ".mobi";
$ext[217] = ".ms";
$ext[218] = ".muni.il";
$ext[219] = ".museum";
$ext[220] = ".mx";
$ext[221] = ".my";
$ext[222] = ".na";
$ext[223] = ".name";
$ext[224] = ".nb.ca";
$ext[225] = ".ne.jp";
$ext[226] = ".ne.kr";
$ext[227] = ".net";
$ext[228] = ".net.au";
$ext[229] = ".net.br";
$ext[230] = ".net.cn";
$ext[231] = ".net.ec";
$ext[232] = ".net.hk";
$ext[233] = ".net.il";
$ext[234] = ".net.in";
$ext[235] = ".net.mm";
$ext[236] = ".net.mx";
$ext[237] = ".net.nz";
$ext[238] = ".net.pl";
$ext[239] = ".net.ru";
$ext[240] = ".net.sg";
$ext[241] = ".net.th";
$ext[242] = ".net.tr";
$ext[243] = ".net.tw";
$ext[244] = ".net.za";
$ext[245] = ".nf.ca";
$ext[246] = ".ngo.za";
$ext[247] = ".nl";
$ext[248] = ".nm.cn";
$ext[249] = ".nm.kr";
$ext[250] = ".no";
$ext[251] = ".no.com";
$ext[252] = ".nom.br";
$ext[253] = ".nom.pl";
$ext[254] = ".nom.ro";
$ext[255] = ".nom.za";
$ext[256] = ".ns.ca";
$ext[257] = ".nt.ca";
$ext[258] = ".nt.ro";
$ext[259] = ".ntr.br";
$ext[260] = ".nu";
$ext[261] = ".nx.cn";
$ext[262] = ".nz";
$ext[263] = ".odo.br";
$ext[264] = ".on.ca";
$ext[265] = ".or.ac";
$ext[266] = ".or.at";
$ext[267] = ".or.jp";
$ext[268] = ".or.kr";
$ext[269] = ".or.th";
$ext[270] = ".org";
$ext[271] = ".org.au";
$ext[272] = ".org.br";
$ext[273] = ".org.cn";
$ext[274] = ".org.ec";
$ext[275] = ".org.hk";
$ext[276] = ".org.il";
$ext[277] = ".org.mm";
$ext[278] = ".org.mx";
$ext[279] = ".org.nz";
$ext[280] = ".org.pl";
$ext[281] = ".org.ro";
$ext[282] = ".org.ru";
$ext[283] = ".org.sg";
$ext[284] = ".org.tr";
$ext[285] = "org.tw";
$ext[286] = ".org.uk";
$ext[287] = ".org.za";
$ext[288] = ".pc.pl";
$ext[289] = ".pe.ca";
$ext[290] = ".pl";
$ext[291] = ".plc.uk";
$ext[292] = ".pm";
$ext[293] = ".ppg.br";
$ext[294] = ".pr";
$ext[295] = ".presse.fr";
$ext[296] = ".priv.pl";
$ext[297] = ".pro";
$ext[298] = ".pro.br";
$ext[299] = ".psc.br";
$ext[300] = ".psi.br";
$ext[301] = ".pt";
$ext[302] = ".qc.ca";
$ext[303] = ".qc.com";
$ext[304] = ".qh.cn";
$ext[305] = ".re";
$ext[306] = ".re.kr";
$ext[307] = ".realestate.pl";
$ext[308] = ".rec.br";
$ext[309] = ".rec.ro";
$ext[310] = ".rel.pl";
$ext[311] = ".res.in";
$ext[312] = ".ro";
$ext[313] = ".ru";
$ext[314] = ".sa.com";
$ext[315] = ".sb";
$ext[316] = ".sc";
$ext[317] = ".sc.cn";
$ext[318] = ".school.nz";
$ext[319] = ".school.za";
$ext[320] = ".se";
$ext[321] = ".se.com";
$ext[322] = ".se.net";
$ext[323] = ".sg";
$ext[324] = ".sh";
$ext[325] = ".sh.cn";
$ext[326] = ".shop.pl";
$ext[327] = ".si.sk";
$ext[328] = ".sk.ca";
$ext[329] = ".sklep.pl";
$ext[330] = ".slg.br";
$ext[331] = ".sn.cn";
$ext[332] = ".sos.pl";
$ext[333] = ".st";
$ext[334] = ".store.ro";
$ext[335] = ".targi.pl";
$ext[336] = ".tc";
$ext[337] = ".tf";
$ext[338] = ".tj";
$ext[339] = ".tj.cn";
$ext[340] = ".tk";
$ext[341] = ".tl";
$ext[342] = ".tm";
$ext[343] = ".tm.fr";
$ext[344] = ".tm.mc";
$ext[345] = ".tm.pl";
$ext[346] = ".tm.ro";
$ext[347] = ".tm.za";
$ext[348] = ".tmp.br";
$ext[349] = ".to";
$ext[350] = ".tourism.pl";
$ext[351] = ".tr";
$ext[352] = ".travel.pl";
$ext[353] = ".tur.br";
$ext[354] = ".turystyka.pl";
$ext[355] = ".tv";
$ext[356] = ".tv.br";
$ext[357] = ".tw";
$ext[358] = ".tw.cn";
$ext[359] = ".ua";
$ext[360] = ".ug";
$ext[361] = ".uk";
$ext[362] = ".uk.co";
$ext[363] = ".uk.com";
$ext[364] = ".uk.net";
$ext[365] = ".us";
$ext[366] = ".us.com";
$ext[367] = ".uy.com";
$ext[368] = ".uz";
$ext[369] = ".vc";
$ext[370] = ".ve";
$ext[371] = ".vet.br";
$ext[372] = ".vg";
$ext[373] = ".web.za";
$ext[374] = ".wf";
$ext[375] = ".ws";
$ext[376] = ".www.ro";
$ext[377] = ".xj.cn";
$ext[378] = ".xz.cn";
$ext[379] = ".yk.ca";
$ext[380] = ".yn.cn";
$ext[381] = ".yt";
$ext[382] = ".za.com";
$ext[383] = ".zj.cn";
$ext[384] = ".zlg.br";

foreach($ext as $value){

echo $_POST["url"];
echo $value;
echo '<br />';

}

?>

Works for me :D
 
0
•••
You enter an url...and it prints it out with every extension?
 
0
•••
Shorty said:
You enter an url...and it prints it out with every extension?

Looks like it, for generating lists for bulk check tools if I'm not mistaken.
 
0
•••
tm said:
Shorty said:
You enter an url...and it prints it out with every extension?

Looks like it, for generating lists for bulk check tools if I'm not mistaken.
Correct. :)
 
0
•••
If you don't have a specific reason for starting your array index at 1 and individually indexing each extension, then the following array would be easier to maintain.

PHP:
<?php

$ext = array(
".com",
".net",
".org",
".info"
);

for ($i=sizeOf($ext); --$i>=0;)  echo $_POST["url"], $ext[$i], '<br />';

?>

If this isn't for personal use only and it's available for public use, be sure to check the value of $_POST["url"] before using it, or at least use htmlentities() on it.

Your method of iterating through the array is fine, I just gave an alternative.

Rich
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back