Unstoppable Domains โ€” AI Assistant

A couple of php related questions

SpaceshipSpaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
1. How would I get a list of variables in an array and make a "select" box?
eg: if I have
PHP:
$array['this'] = "asd";
$array['that'] = "admmfmf";
how would I make a selection box like this:
Code:
<select>
<option>this</option>
<option>that</option>
</select>

2. How would I determine if a string was an ip address or not?

Thanks a lot
Tom
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
1) What i would do it:

PHP:
$this = "asd";
$that = "sdfsdfdf";

Then the form:
HTML:
<select>
<option>$this</option>
<option>$that</option>

Hope this is what your looking for, im not sure if it is.
 
0
•••
no, sorry, I don't explain things very well.

I have a variable called $tlds

so I have:
- $tlds["co.uk"]
- $tlds["com"]
- $tlds["net"]
etc...

each contain that specific tld's server (ie: $tlds["co.uk"] = "whois.server.com";).

In my whois script I have a form. In the form I have a text input and a select input. So basically, people type in the domain and choose the tld, eg: they type "namepros" and then choose ".com" from the drop down box. Now, I want to keep adding tlds and stuff to my list of servers, but don't want to have to go into the select box code each time, and it would be much better if I could just get the "xxx" bit of the $tld["xxx"] for each one and dynamically build a select box each time. Is this possible? It would also be much better if they could be arranged alphabetically...

Thanks
Tom
 
0
•••
This should check if an ip is formatted properly:
PHP:
<?php
$ipaddress='128.0.0.1';
if (preg_match("/^(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)$/", $ipaddress,$match)) 
  echo "Valid IP Address";
else
  die("Invalid IP Address");
?>
 
0
•••
So basically you have: array("com" => "whois.server.com", "net" => "whois.server.com", "org" => "whois.server.com"); etc? Or maybe I'm mistaken..

Well, if this is the case:
PHP:
<?php

foreach($tlds as $tld => $server)
{
  echo '<option value="'.$tld.'">'.$tld.'</option>'."\n";
}

?>
 
0
•••
Jim_ said:
This should check if an ip is formatted properly:
PHP:
<?php
$ipaddress='128.0.0.1';
if (preg_match("/^(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)\\.(25[0-5]|2[0-4]\d|[01]?\d\d|\d)$/", $ipaddress,$match)) 
  echo "Valid IP Address";
else
  die("Invalid IP Address");
?>
thanks a lot that will help, but first I need to distinguish an ip address from a domain name. Will "."s matter if I use "is_numeric()"?
SecondVersion said:
So basically you have: array("com" => "whois.server.com", "net" => "whois.server.com", "org" => "whois.server.com"); etc? Or maybe I'm mistaken..

Well, if this is the case:
PHP:
<?php

foreach($tlds as $tld => $server)
{
  echo '<option value="'.$tld.'">'.$tld.'</option>'."\n";
}

?>
works.... thanks
 
0
•••
PoorDoggie said:
thanks a lot that will help, but first I need to distinguish an ip address from a domain name. Will "."s matter if I use "is_numeric()"?

The easiest thing to do would be to check if it was an ip address then if not check if it is a valid domain name.

Also I am not sure if a . will affect is_numeric or if it will take out the .'s (but my guess is that it will show false). BUT if it does show true this would not necessarily mean that the string is a possible ip address, if is_numeric is ok with multiple .'s 266.266.266.266 would work but an ip address can only be between 0 and 255 between each .
 
0
•••
I'm pretty sure is_numeric would return false for an ip.

Just check if its a domain name format if it isn't an ip.

'/^[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i'
I think that string pattern should work for checking if something is a valid domain name format.
 
0
•••
great... thanks! :)
 
0
•••
Spaceship
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back